Can I use a Coffeescript switch block in the eco templating engine? I tried a couple of variations, but I keep getting unexpected dedent errors.
Update: To appease the downvoters, here is what I expected to work
<% switch x : %>
<% when 1 : %>
one
<% end %>
<% when 2 : %>
two
<% end %>
<% end %>
But I get "Parse error on line 5: unexpected dedent"
ECO templates don't appear to support the switch statement.
The generated CoffeeScript code for your code is:
switch x
__out.push '\n'
when 1
__out.push '\n one\n'
__out.push '\n'
when 2
__out.push '\n two\n'
__out.push '\n'
The two __out.push '\n' lines after switch x and the end of the second when statement don't seem to allow this CoffeeScript snippet to compile into JavaScript.
Looking through the code, I couldn't figure out how to prevent those lines from being printed. This might be a good bug to report to the guys that make eco.
I'm only somewhat familiar with eco, but it seems as though it would just not be creating the right CS from that expression. Considering CS uses when x then y, I'm not sure you're getting that on compile.
You could try this instead:
<% switch x : %>
<% when 1 then: %>
one
<% end %>
<% when 2 then: %>
two
<% end %>
<% end %>
Related
I've got a multi-dimensional hash that I'm trying to print out in a table. I can't get the referencing / dereferencing right.
I'm putting an excel spreadsheet into the hash and I want to print out the corresponding rows and columns in html and match the rows/columns of the spreadsheet (some of which are empty).
I'm using Perl Dancer and Template Toolkit. On the server side the hash works fine. print $big_table{$column}{$row}; on the server side and it prints the correct column and row with NO issues.
On the client side, the 0, 1, 2... are supposed to be the columns. Some columns are blank so I can't just print the contents.
The way it is now it prints ARRAY(0x3e5389c). I tried a different way and it printed HASH...
I know I've got some reference/dereference issues. Any advice would be welcome.
Server Side Code:
my %big_table = ();
# $cell->value() is the text ripped from the excel cell at that location
$big_table{$column}{$row} = $cell->value();
template 'index', { big_table => \%big_table };
Client Side:
<Table border="3">
<% FOREACH n IN big_table.0 %>
<TR><TD> <% big_table.0.keys %> <TD> <% big_table.1.keys %>
 <TD> <% big_table.2.keys %> <TD> <% big_table.3.keys %>
  <TD> <% big_table.4.keys %>
 <TD> <% big_table.5.keys %> 
<% END %>
</Table>
Thanks in advance!
Got it working.
Changed to an array. '$big_table[$col][$row] = $cell->value();' and populated a second array with all the row #'s.
The Client looks like
<% FOREACH r IN row_numbers %>
<TR><TD>   <% big_table.0.$r %>   <TD>   <% big_table.1.$r %>...
<% END %>
Works great but it's probably crazy in-effecient :(. The spreadsheet is 800 rows long so it's a 2nd array with 800 elements just to iterate over 'FOREACH' loop.
I'm trying to create a custom menu with TypoScript, I have 8 MenĂ¼ items an d I want to remove the css class "dropdown_1column and dropdown_1column" for the first 2 items and I do not know how?
I have experienced that it is with the Typoscript onSplit function possible,
whats wrong in this code?
wrap = <ul class="levels">|</ul>|| <ul class="levels">|</ul>|*|<div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>||<ul class="levels">|</ul>
The first two items should be wrapped in:
<ul class="levels">|</ul>
The remaining items should be wrapped in:
<div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
here ist my html output:
<li>
<a class="drop" href="blblbl/">item</a>
<div class="dropdown_1column">
<div class="col_1 firstcolumn">
<ul class="levels">
<li>
<li>
<li>
</ul>
</div>
</li>
and it must be so
<li>
<a class="drop" href="blblbl/">item</a>
<div>
<div>
<ul class="levels">
<li>
<li>
<li>
</ul>
</div>
</li>
Thank You for Help.
I'd say that no one has read TSref here :)
What you need:
According to 4th rule of optionSplit 1:
"if the last part is absent, the middle value is repeated"
So the most elegant and shortest optionSplit syntax will be:
first || second |*| the_rest
In Typoscript code it will be something like:
<ul class="levels">|</ul> || <ul class="levels">|</ul> |*| <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
What you got:
The optionSplit you wrote has syntax like this:
F || S |*| M1 || M2
which produces menu like:
F S M1 M2 M1 M2 M1 M2....
because the (the last, or if absent) the middle part is repeated continuously after the first part.
For more about optionSplit.
You could either go fo optionSplit to format items based on their position or you could split the menu in two parts and use begin and maxItems to define the range of items to use.
The latter is less sophisticated but should serve you well:
10 = COA
10 {
10 = HMENU
10 {
# your menu definition here
maxItems = 2
wrap = <ul class="levels">|</ul>
}
20 = HMENU
20 {
# your menu definition here
begin = 3
wrap = <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
}
}
Your option split syntax is wrong. It must be first |*| middle |*| last. Elements are filed in beginning from last. You can further split each property by a double pipe (||).
first || second |*| middle |*| second last || last
Thus it should be
wrap = <ul class="levels">|</ul>|| <ul class="levels">|</ul>|*| <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div> |*| <div class="dropdown_1column"><div class="col_1 firstcolumn"><ul class="levels">|</ul></div></div>
which has the format
first || second |*| middle |*| last
whereas the middle and the last part share the same code
I am parsing one file which has some html tag and changing into latex tag.
cat text
<Text>A <strong>ASDFF</strong> is a <em>cerebrovafdfasfscular</em> condifasdftion caufadfsed fasdfby tfdashe l
ocfsdafalised <span style="text-decoration: underline;">ballooning</span> or difdaslation of an arfdatery in thdfe bfdasrai
n. Smadfsall aasdneurysms may dadisplay fdasno ofadsbvious sdfasigns (<span style="text-decoration: underline;"><em><str
ong>asymptomatic</strong></em></span>) bfdasut lfdsaarger afdasneurysms maydas besda asfdsasociated widfth sdsfudd
sed -e 's|<strong>\(.*\)</strong>|\\textbf{\1}|g' test
cat out
<Text>A \textbf{ASDFF</strong> is a <em>cerebrovafdfasfscular</em> condifasdftion caufadfsed fasdfby tfdashe locfsda
falised <span style="text-decoration: underline;">ballooning</span> or difdaslation of an arfdatery in thdfe bfdasrain. Sma
dfsall aasdneurysms may dadisplay fdasno ofadsbvious sdfasigns (<span style="text-decoration: underline;"><em><strong>
;asymptomatic}</em></span>) bfdasut lfdsaarger afdasneurysms maydas besda asfdsasociated widfth sdsfudd
Expected outputs should be \textbf{ASDFF} while i observe \textbf{ASDFF .........}. How to get expected result?
Regards
You may want to use perl regex instead.
perl -pe 's|<strong>(.*?)</strong>|\\textbf{\1}|g'
Your problem is similar with non-greedy-regex-matching-in-sed. And next time you may want to simplify your case to point out the real problem. For example, don't just paste the raw html code, use this instead:
fooTEXT1barfooTEXT2bar
Update
If you just want the greedy approach, just ignore this.
I did find a way to capitalize the whole document, with both sed and awk, but how to do it, if I want to convert everything inside patterns from CAPS LOCK to Capital?
For example, I have an HTML file, and everything (multiple occurrences) between <b> and </b> has to be converted from TITLE to Title, and if possible making small words (1 ~ 2 letters) in lowercase.
From This:
<div id="1">
<div class="p"><b>THIS IS A RANDOM TITLE</b></div>
<table class="hugetable">
...
</table>
<div class="p"><b>THIS IS ANOTHER RANDOM TITLE</b></div>
<table class="hugetable">
...
</table>
...
</div>
To this:
<div id="1">
<div class="p"><b>This is a Random Title</b></div>
<table class="hugetable">
...
</table>
<div class="p"><b>This is Another Random Title</b></div>
<table class="hugetable">
...
</table>
...
</div>
This is not the most beautiful solution but I think it works:
sed -r -e '/<b>/ {s/( .)([^ ]*)/\1\L\2/g}' -e 's/<b>(.)/<b>\u\1/' -e '/<b>/ {s/(\b.{1,2}\b)/\L\1/g}' data
Explanation:
1st expression (-e): If a line contains <b>:
Then for each word which has a space in front of it, keep the space and the first (already capitalized) character (\1) and then convert all the following characters of the word to lower case (\L\2)
2nd expression (-e): The first word after <b> is still uncapitalized, so select the first character after the bold tag <b>(.) and replace it uppercased <b>\u\1
3rd expression (-e): Again if a line contains <b>:
Then select words of 1 or 2 characters in length \b.{1,2}\b and replace them lowercased \L\1
I was trying to create a custom menu in TypoScript and my idea is to have a div for each menu item.
Example
lib.mainMenu = HMENU
lib.mainMenu {
entryLevel = 0
1 = TMENU
1 {
NO.allWrap = <div id="forsideknap">|</div> |*| <div id="butikker">|</div> |*| <div id="nyheder">|</div> |*| <div id="arrangementer">|</div> |*| <div id="avis">|</div>
}
}
I have created 5 pages, and only 3 of them are getting their div. There are 3 identical. How can I fix this problem?
You are using the optionSplit concept, which itself has many different options. It might cause confusion when used for the first time. You unintentionally defined the first, the middle and the last part of your wrap by using the |*| separators:
first element |*| middle element(s) |*| last element
If there is more then one middle element, they all get the middle parameter ("butikker"). And everything from the third |*| on is ignored.
What you wanted is a simple sequence of different wraps. This is achieved by using the || separator:
1st element || 2nd element || 3rd element || 4th element || 5th element || etc.
In your case:
NO.allWrap = <div id="forsideknap">|</div> || <div id="butikker">|</div> || <div id="nyheder">|</div> || <div id="arrangementer">|</div> || <div id="avis">|</div>
Note that you can combine the separators if you have more complicated structures.
Read more:
on the TYPO3 wiki page about optionSplit
on TYPO3 Docs
German tutorial on optionSplit in an HMENU / TMENU