sudo gem install w2tags http://rubyforge.org/projects/w2tags/
Release Name: 0.9.3 http://rubyforge.org/frs/shownotes.php?group_id=6464&release_id=33258 Enjoy.... /wh e=mc2inhologram Notes: W2Tags is the way to tags, a short cut / macros. When it do, it use some patern define in HOT file to produce tags from minimal code to become full fledge tags. Syntax mimics HAML to easy transisition, and proven to be useable and best. HAML like: ~~~~~~~~~~ %h1 New user = error_messages_for :user -form_for @user do |f| %p %b Name %br = f.text_field :name %p %b Email %br = f.text_field :email %p %b Last login %br = f.datetime_select :last_login %p = f.submit "Create" = link_to 'Back', users_path You can see that it not DRY, some patern will go to HOT files “rails_basic.hot“ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>_input %p %b $0.capitalize.gsub('_',' ')- %br = f.text_field :$0 >>_submit !/ %p = f.submit "$0" and code in source: ~~~~~~~~~~~~~~~~~~~ !hot!rails_basic %h1 New user = error_messages_for :user -form_for @user do |f| -input name;email;last_login -submit Create = link_to 'Back', users_path ==HILIGHT== ~~~~~~~~~~~ SINATRA HOOK ~~~~~~~~~~~~ sinatra usualy consist only one file “main.rb“, so just add below sinatra require: require 'w2tags' require 'w2tags/sinatra_hook' RAILS HOOK ~~~~~~~~~~ add inside file “config/environment.rb“ in the bottom: require 'w2tags' require 'w2tags/rails_hook' OR You can add + add Scaffold Plugins by using command: w2tags -rails ./script/generate w2scaffold post title:string body:text published:boolean PASS TEST on Linux Ubuntu 8.10 and win32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test for 57 assertions on: Linux Ubuntu 8.10 Ruby 1.8.x Win32 MinGW Ruby 1.9.1 FIX COMPATIBLE between ruby 1.8.x and 1.9.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modular, Plugin for Block ~~~~~~~~~~~~~~~~~~~~~~~~~ this will make it easy to integerate with another parser like minimalist SASS (66-4)LOC: %head ~~~ #main :width 97% p, div :font-size 2em a, li :font-weight bold pre :font-size 3em a :font-weight bold :text-decoration none &:hover :text-decoration underline &:visited :border thin 1px blue :font :weight normal :size 2em #main :width 90% #sidebar :float left :margin-left 20% .ie6 & :margin-left 40% %body <head> <style> #main{ width:97%; } #main p,#main div{ font-size:2em; } #main p a,#main p li,#main div a,#main div li{ font-weight:bold; } #main pre{ font-size:3em; } a{ font-weight:bold; text-decoration:none; } a:hover{ text-decoration:underline; } a:visited{ border:thin 1px blue; font-weight:normal; font-size:2em; } #main{ width:90%; } #main #sidebar{ float:left; margin-left:20%; } .ie6 #main #sidebar{ margin-left:40%; } </style> </head> <body> </body> Run on IRB ~~~~~~~~~~ C:\>w2tags -irb ARGV : -irb Your W2Tags instance object stored in WH... Ex: puts WH.parse_line("#content\n %span Hello") Shortcut command => wh("#content\n %span Hello") irb(main):001:0> wh(<<END) irb(main):002:0" #wow irb(main):003:0" #kereen irb(main):004:0" %span Hello World irb(main):005:0" END =>C:/mingw/lib/ruby/gems/1.9.1/gems/w2tags-0.9.1/hot/html.hot <div id="wow"> <div id="kereen"> <span>Hello World</span> </div> </div> => nil irb(main):006:0> List of HAML Like command: ~~~~~~~~~~~~~~~~~~~~~~~~~~ % Tag formating # div formating with attribute id . div formating with attribute class \ line text / no parsing - translate to Ruby code = translate to Ruby code == translate to Ruby String -# block remark / comment not include on result -! block not parse List of W2TAGS command: ~~~~~~~~~~~~~~~~~~~~~~~ : input formating with attribute name ^ shortcut for NextTag in html ~^ re-assign shortcut for NextTag in html < disable auto close tags when last params has char "<" &var= define variable for it use later on params inside w2tags command &var! use variable on params inside w2tags command @var= define variable with uniq value for it use later on params inside w2tags command @var! use variable with uniq value on params inside w2tags command ~~~ SASS Block InLine Parsing (%tag text%) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ that's the first question came in FAQ on HAML, and I think this implementation fit in my brain and it cover the Key-Variable too. Lets see some example from minimal inline to inline with Key-Variable: I Like (%b cake%)! I Like (%span.b cake%)! I Like (%strong.bold{banana="boys"} a(%i.italic cake%)%)! I Like <b>cake</b>! I Like <span class="b">cake</span>! I Like <strong class="bold" banana="boys">a<i class="italic">cake</i></strong>! Var-Constanta available in HOT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ when parsing line as a HOT command, you can combine your code with this var Example: %div&joel:name#id.class{op="atribute"}== info $$ => full Key-Variable ( :name#id.class{op="atribute"}== ) $& => Variable for HOT ( &joel ) $: => name-Variable ( :name ) $# => id-Variable ( #id ) $. => class-Variable ( .class ) $@ => attribute-Variable ( {op="atribute"} ) *& => Variable for HOT ( joel ) *: => name-Variable ( name ) *# => id-Variable ( id ) *. => class-Variable ( class ) *@ => class-Variable ( op="atribute" ) *att* => attribute-Variable ( op="atribute" ) *all* => all-Variable ( name="name" id="id" class="class" op="atribute" ) *name* => name-Variable ( name="name" ) *id* => id-Variable ( id="id" ) *class*=> class-Variable ( class="class" ) Sample erb.hot with optional Value => ~ $0 ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>input <input *all*~value="$0"~/> Key-Variable are attribute attach to tag like :name, #id and .class and now you can assign that id without value %input:address#.light :address#.light :user.address#.light :user.address#.light Tokyo <input name="address" class="light" /> <input name="address" class="light" /> <input name="user.address" class="light" /> <input name="user.address" class="light" value="Tokyo"/> PARAMETERS VARIABLE (MAX:9) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ $*, $0 - $9. When you invoke HOT command like “-all_params one;two;three;four” you are invoking HOT command with 4 parameters ($0,$1,$2,$3), and the translation will be done like sample below: >>_all_params <div>$*</div> -magic $* $1 $0 >>_magic <magic>$0</magic> $* meaning: this variable will be fill-in after all parameters got fill-in, as example we supply 4 parameters and parameters fill in to variable only two ($0 = “one”, $1 = “two”) the rest will go to variable $* = “three;four“ !hot!test -all_params one;two;three;four <div>three;four</div> <magic>three</magic> <magic>four</magic> two one remember passing paramter to HOT doesn’t mean that variable must start from zero, its only a guide that you can have multiple params to pass in correct order see sample after change the HOT but the result still the same >>_all_params <div>$*</div> -magic $* $4 $3 >>_magic <magic>$4</magic> PARAMETERS VARIABLE translate to RUBY CODE ( =$0 ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ some time it need a block of ruby code / ruby string code inside attribute of tag but it must be simple and easy to remember the command and this is how the implementation >>_form %form{action="=$0"} -form edit <form action="<%= edit %>"> </form> PARAMETERS VARIABLE translate to RUBY STRING CODE ( ==$0 ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>_form2 %form{action="==$0"} -form edit/1 <form action="<%= "edit/1" %>"> </form> PARAMETERS VARIABLE INTERPOLATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ you can do interpolation on variable >>_all_params <div>$*</div> -magic $* $4 $3 >>_magic <magic> $4.upcase.reverse~ </magic> !hot!test -all_params one;two;three;four <div>three;four</div> <magic> EERHT </magic> <magic> RUOF </magic> two one ^ shortcut for NextTag in html ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ when you type ul tag, commonly it follow the li tag and this is the benefit of using this command. Predefine shortcut are: %html => %head $* %head => %body $* %ol => %li $0 %ul => %li $0 %dl => %dt $0 %dd => %dt $0 %form => %input $0 %select => %option $0 %tr => %th $0 #first line %tr => %td $0 #after first line Basic Example: %ul ^ this is a bullet list 1 ^ this is a bullet list 2 ; this is a bullet list 3 <ul> <li>this is a bullet list 1</li> <li>this is a bullet list 2</li> <li>this is a bullet list 3</li> </ul> With Attribute: %ul ^.hilite{wow="kereen"} this is a bullet list 1 ^.hilite{wow="kereen"} this is a bullet list 2 ; this is a bullet list 3 <ul> <li class="hilite" wow="kereen">this is a bullet list 1</li> <li class="hilite" wow="kereen">this is a bullet list 2</li> <li class="hilite" wow="kereen">this is a bullet list 3</li> </ul> ~^ re-assign shortcut for NextTag in html ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sometime I need result from shortcut for NextTag already include class or attribut and this command play. %ul ~^%li.hilite{wow="kereen"} ^ this is a bullet list 1 ^ this is a bullet list 2 ; this is a bullet list 3 <ul> <li class="hilite" wow="kereen">this is a bullet list 1</li> <li class="hilite" wow="kereen">this is a bullet list 2</li> <li class="hilite" wow="kereen">this is a bullet list 3</li> </ul> or you can put this command to a HOT file and it will use just like regular W2TAGS command >>_ul %ul ~^%li.hilite{wow="kereen..."} !hot!common -ul ^ this is a bullet list 1 ^ this is a bullet list 2 ; this is a bullet list 3 <ul> <li class="hilite" wow="kereen...">this is a bullet list 1</li> <li class="hilite" wow="kereen...">this is a bullet list 2</li> <li class="hilite" wow="kereen...">this is a bullet list 3</li> </ul> Var and Unique Var set and get ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @myvar=one;two;three @myvar=five;one;two %ul ^ @myvar! <ul> <li>one</li> <li>two</li> <li>three</li> <li>five</li> </ul> Changes: = Change Log Below is a complete listing of changes for each revision of W2TAGS. == 0.9.3 === Pass test on Linux Ubuntu 8.10 and win32 test for 57 assertions on: Linux Ubuntu 8.10 Ruby 1.8.x Win32 Ruby 1.9.1 === Fix Compatible between ruby 1.8.x and 1.9.1 "test var"[-1] # only work on ruby 1.9.1 "test var"[-1,1] # worked! === Split Code to new file for w2tags Block not parsing When I need to implement Sass Parser on w2tags Block not parsing its best way to seperate to new file for (plain_text, remark, sass). === Implement Simple Sass Parser Its my need for simple Sass Parser, focus on DRY up the Sass code, calculation color, global variable not implement. === update erb.hot now you can make "a href" more readable with var in Key-Variable OLD: ~~~~ >>_a %a$${href="#"} $* NEW: ~~~~~ >>_a %a$${href="*&"} $* -a&/ Home => <a href="/">Home</a> -a&/post/edit Edit => <a href="/post/edit">Edit</a> ------------------------------------ ID-Ruby Berdiskusi dan belajar bersama Bahasa Pemrograman Ruby, termasuk segala varian Ruby (JRuby, Rubinius, IronRuby, XRuby), dan program yang dibuat dengan Ruby (Ruby on Rails, JRuby on Rails, Merb) <*> Kunjungi *arsip milis* id-ruby di http://groups.yahoo.com/group/id-ruby/messages http://www.mail-archive.com/[email protected]/ http://rubyurl.com/Q8DD http://news.gmane.org/gmane.comp.lang.ruby.region.indonesia <*> Baca peraturan id-ruby sebelum posting http://rubyurl.com/gay1 <*> Ikutilah Jajak Pendapat ID-Ruby http://rubyurl.com/3CCt <*> Links ID-Ruby http://rubyurl.com/n96r <*> Database ID-Ruby http://rubyurl.com/Iw3u <*> Kunjungi Situs Resmi Ruby Indonesia http://www.ruby-lang.org/id/ <*> Join Ruby Indonesia on Facebook http://rubyurl.com/QV48 <*> Join Ruby Indonesia on LinkedIn http://rubyurl.com/eh0i Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/id-ruby/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/id-ruby/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

