Changeset 80

Show
Ignore:
Timestamp:
10/03/2006 15:57:42 (2 years ago)
Author:
why
Message:
  • README: updated all rdoc and package docs to 0.5 and its conventions.
Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG

    r20 r80  
     1= 0.5 
     2=== 03 October, 2006 
     3 
     4* XHTML Validation built in.  So, if you have an invalid tag: error.  Invalid attribute: error. 
     5  And two identical IDs in the same document: error.  Optional, of course.  But handy! 
     6* New Markaby::Fragment class adds much flexibility.  If it discovers you are using a tag as a string, 
     7  the tag is removed from the stream.  (<tt>div { strong("Real") + " Giraffes" }</tt>) 
     8* The prevailing rule now is: if you want it escaped, pass it to a block.  If not, pass it as an arg. 
     9* Again, escaped: <tt>h1("Me & You Have a Giraffe")</tt> 
     10* And, not escaped: <tt>h1 { "<a href='/'>Home</a>" }</tt> 
     11* Less method_missing, meaning: faster calls all around.  Tag methods generated based on doctype. 
     12* The <tt>html</tt> method doesn't write the doctype tags and meta tags.  You must use <tt>xhtml_transitional</tt> or <tt>xhtml_strict</tt> methods to do that. 
     13* The <tt>img</tt> method doesn't try to inject an empty alt tag and a zero border.  No more of that. 
     14 
    115= 0.3 
    216=== 02nd February, 2006 
  • trunk/README

    r60 r80  
    7474module where it won't mix with anything. 
    7575 
    76 = A Note About Rails Helpers 
    77  
    78 When used in Rails templates, the Rails helper object is passed into  
    79 Markaby::Builder.  When you call helper methods inside Markaby, the output 
    80 from those methods will be output to the stream.  This is incredibly 
    81 handy, since most Rails helpers output HTML tags. 
    82  
    83   head do 
    84     javascript_include_tag 'prototype' 
    85     autodiscovery_link_tag 
    86   end 
    87  
    88 However, some methods are designed to give back a String which you can use 
    89 elsewhere.  Call the <tt>@helpers</tt> object with the method and you'll get 
    90 the String back and nothing will be output. 
    91  
    92   p "Total is: #{@helper.number_to_human_size @file_bytes}" 
    93  
    94 Conversely, you may call instance variables from your controller by using 
    95 a method and its value will be returned, nothing will be output. 
    96  
    97   # Inside imaginary ProductController 
    98   def list 
    99     @products = Product.find :all 
    100   end 
    101  
    102   # Inside app/views/product/list.mab 
    103   products.each do |product| 
    104     p product.title 
    105   end 
    106  
    107 = A Quick Tour 
     76= The Six Steps of Markaby 
    10877 
    10978If you dive right into Markaby, it'll probably make good sense, but you're 
    110 likely to run into a few kinks.  Keep these pointers in mind and everything 
    111 will be fine. 
    112  
    113 == Element Classes 
     79likely to run into a few kinks.  Why not review these six steps and commit 
     80them memory so you can really *know* what you're doing? 
     81 
     82== 1. Element Classes 
    11483 
    11584Element classes may be added by hooking methods onto container elements: 
     
    12998  </div> 
    13099 
    131 == Element IDs 
     100== 2. Element IDs 
    132101 
    133102IDs may be added by the use of bang methods: 
     
    147116  </div> 
    148117 
    149 == Markaby assumes XHTML 1.0 Transitional  
    150  
    151 Output defaults to XHTML 1.0 Transitional. To do XHTML 1.0 Strict, 
    152 try this: 
     118== 3. Validate Your XHTML 1.0 Output  
     119 
     120If you'd like Markaby to help you assemble valid XHTML documents, 
     121you can use the <tt>xhtml_transitional</tt> or <tt>xhtml_strict</tt> 
     122methods in place of the normal <tt>html</tt> tag. 
    153123 
    154124  xhtml_strict do 
    155     # innerds 
    156   end 
    157  
    158 == Markaby prevents invalid HTML 
    159  
    160 Since Markaby knows which doctype you're using, it checks a big 
     125    head { ... } 
     126    body { ... } 
     127  end 
     128 
     129This will add the XML instruction and the doctype tag to your document. 
     130Also, a character set meta tag will be placed inside your <tt>head</tt> 
     131tag. 
     132 
     133Now, since Markaby knows which doctype you're using, it checks a big 
    161134list of valid tags and attributes before printing anything. 
    162135 
     
    166139  InvalidHtmlError: no such attribute `styl' 
    167140 
    168 == Auto-stringification 
     141Markaby will also make sure you don't use the same element ID twice! 
     142 
     143== 4. Escape or No Escape? 
     144 
     145Markaby uses a simple convention for escaping stuff: if a string 
     146is an argument, it gets escaped.  If the string is in a block, it 
     147doesn't. 
     148 
     149This is handy if you're using something like RedCloth or 
     150RDoc inside an element.  Pass the string back through the block 
     151and it'll skip out of escaping. 
     152 
     153  div.comment { RedCloth.new(str).to_html } 
     154 
     155But, if we have some raw text that needs escaping, pass it in 
     156as an argument: 
     157 
     158  div.comment raw_str 
     159 
     160One caveat: if you have other tags inside a block, the string 
     161passed back will be ignored. 
     162 
     163  div.comment { 
     164    div.author "_why" 
     165    div.says "Torpedoooooes!" 
     166    "<div>Silence.</div>" 
     167  } 
     168 
     169The final div above won't appear in the output.  You can't mix 
     170tag modes like that, friend. 
     171 
     172== 5. Auto-stringification 
    169173 
    170174If you end up using any of your Markaby "tags" as a string, the 
     
    192196    join( " | " ) 
    193197 
    194 == The <tt>tag!</tt> Method 
     198== 6. The <tt>tag!</tt> Method 
    195199 
    196200If you need to force a tag at any time, call <tt>tag!</tt> with the 
     
    204208  end 
    205209 
     210= A Note About Rails Helpers 
     211 
     212When used in Rails templates, the Rails helper object is passed into  
     213Markaby::Builder.  When you call helper methods inside Markaby, the output 
     214from those methods will be output to the stream.  This is incredibly 
     215handy, since most Rails helpers output HTML tags. 
     216 
     217  head do 
     218    javascript_include_tag 'prototype' 
     219    autodiscovery_link_tag 
     220  end 
     221 
     222However, some methods are designed to give back a String which you can use 
     223elsewhere.  That's okay!  Every method returns a Fragment object, which can 
     224be used as a string. 
     225 
     226  p { "Total is: #{number_to_human_size @file_bytes}" } 
     227 
     228Also see the Quick Tour above, specifically the stuff about auto-stringification. 
     229 
     230If for any reason you have trouble with fragments, you can just 
     231call the <tt>@helpers</tt> object with the method and you'll get 
     232the String back and nothing will be output. 
     233 
     234  p { "Total is: #{@helper.number_to_human_size @file_bytes}" } 
     235 
     236Conversely, you may call instance variables from your controller by using 
     237a method and its value will be returned, nothing will be output. 
     238 
     239  # Inside imaginary ProductController 
     240  def list 
     241    @products = Product.find :all 
     242  end 
     243 
     244  # Inside app/views/product/list.mab 
     245  products.each do |product| 
     246    p product.title 
     247  end 
     248 
    206249= Credits 
    207250 
  • trunk/Rakefile

    r77 r80  
    99 
    1010REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil 
    11 VERS = ENV['VERSION'] || "0.4" + (REV ? ".#{REV}" : "") 
     11VERS = ENV['VERSION'] || "0.5" + (REV ? ".#{REV}" : "") 
    1212 
    1313task :default => [:package] 
  • trunk/lib/markaby.rb

    r74 r80  
    2020#   proper templating language. 
    2121module Markaby 
    22   VERSION = '0.4' 
     22  VERSION = '0.5' 
    2323 
    2424  class InvalidXhtmlError < Exception; end 
  • trunk/lib/markaby/builder.rb

    r78 r80  
    162162    end 
    163163 
    164     # Create XML markup based on the name of the method +sym+. This method is never  
    165     # invoked directly, but is called for each markup method in the markup block. 
    166     # 
    167     # This method is also used to intercept calls to helper methods and instance 
     164    # This method is used to intercept calls to helper methods and instance 
    168165    # variables.  Here is the order of interception: 
    169166    # 
    170     # * If +sym+ is a recognized HTML tag, the tag is output 
    171     #   or a CssProxy is returned if no arguments are given. 
    172     # * If +sym+ appears to be a self-closing tag, its block 
    173     #   is ignored, thus outputting a valid self-closing tag. 
     167    # * If +sym+ is a helper method, the helper method is called 
     168    #   and output to the stream. 
     169    # * If +sym+ is a Builder::XmlMarkup method, it is passed on to the builder object. 
    174170    # * If +sym+ is also the name of an instance variable, the 
    175171    #   value of the instance variable is returned. 
    176     # * If +sym+ is a helper method, the helper method is called 
    177     #   and output to the stream. 
    178     # * Otherwise, +sym+ and its arguments are passed to tag! 
     172    # * If +sym+ has come this far and no +tagset+ is found, +sym+ and its arguments are passed to tag! 
     173    # * If a tagset is found, though, +NoMethodError+ is raised. 
     174    # 
     175    # method_missing used to be the lynchpin in Markaby, but it's no longer used to handle 
     176    # HTML tags.  See html_tag for that. 
    179177    def method_missing(sym, *args, &block) 
    180178      if @helpers.respond_to?(sym, true) && !self.class.ignored_helpers.include?(sym) 
    181179        r = @helpers.send(sym, *args, &block) 
    182         if @output_helpers 
     180        if @output_helpers and r.respond_to? :to_str 
    183181          fragment { @builder << r } 
    184182        else 
     
    196194    end 
    197195 
     196    # Every HTML tag method goes through an html_tag call.  So, calling <tt>div</tt> is equivalent 
     197    # to calling <tt>html_tag(:div)</tt>.  All HTML tags in Markaby's list are given generated wrappers 
     198    # for this method. 
     199    # 
     200    # If the @auto_validation setting is on, this method will check for many common mistakes which 
     201    # could lead to invalid XHTML. 
    198202    def html_tag(sym, *args, &block) 
    199203      if @auto_validation and @tagset.self_closing.include?(sym) and block 
     
    263267  end 
    264268 
     269  # Every tag method in Markaby returns a Fragment.  If any method gets called on the Fragment, 
     270  # the tag is removed from the Markaby stream and given back as a string.  Usually the fragment 
     271  # is never used, though, and the stream stays intact. 
     272  # 
     273  # For a more practical explanation, check out the README. 
    265274  class Fragment < ::Builder::BlankSlate 
    266275    def initialize(s, a, b) 
  • trunk/lib/markaby/tags.rb

    r79 r80  
    77  # Common sets of attributes. 
    88  AttrCore = [:id, :class, :style, :title] 
    9   AttrI18n = [:lang, :'xml:lang', :dir] 
     9  AttrI18n = [:lang, 'xml:lang'.intern, :dir] 
    1010  AttrEvents = [:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover, :onmousemove,  
    1111      :onmouseout, :onkeypress, :onkeydown, :onkeyup] 
     
    2626      :title => AttrI18n + [:id], 
    2727      :base => [:href, :id], 
    28       :meta => AttrI18n + [:id, :http, :name, :content, :scheme, :'http-equiv'], 
     28      :meta => AttrI18n + [:id, :http, :name, :content, :scheme, 'http-equiv'.intern], 
    2929      :link => Attrs + [:charset, :href, :hreflang, :type, :rel, :rev, :media], 
    30       :style => AttrI18n + [:id, :type, :media, :title, :'xml:space'], 
    31       :script => [:id, :charset, :type, :src, :defer, :'xml:space'], 
     30      :style => AttrI18n + [:id, :type, :media, :title, 'xml:space'.intern], 
     31      :script => [:id, :charset, :type, :src, :defer, 'xml:space'.intern], 
    3232      :noscript => Attrs, 
    3333      :body => Attrs + [:onload, :onunload], 
     
    4242      :address => Attrs, 
    4343      :hr => Attrs, 
    44       :pre => Attrs + [:'xml:space'], 
     44      :pre => Attrs + ['xml:space'.intern], 
    4545      :blockquote => Attrs + [:cite], 
    4646      :ins => Attrs + [:cite, :datetime], 
     
    4848      :a => Attrs + AttrFocus + [:charset, :type, :name, :href, :hreflang, :rel, :rev, :shape, :coords], 
    4949      :span => Attrs, 
    50       :bdo => AttrCore + AttrEvents + [:lang, :'xml:lang', :dir], 
     50      :bdo => AttrCore + AttrEvents + [:lang, 'xml:lang'.intern, :dir], 
    5151      :br => AttrCore, 
    5252      :em => Attrs,