Module: Murlsh::Markup
- Included in:
- UrlBody
- Defined in:
- lib/murlsh/markup.rb
Overview
Helper mixin for XML builder.
Instance Method Summary collapse
-
#atom(href) ⇒ Object
ATOM feed link builder.
-
#css(hrefs, options = {}) ⇒ Object
CSS link builder.
-
#form_input(options) ⇒ Object
Form input builder.
-
#javascript(sources, options = {}) ⇒ Object
Javascript link builder.
-
#metas(tags) ⇒ Object
Meta tag builder.
-
#murlsh_img(options = {}) ⇒ Object
Image tag builder.
Instance Method Details
#atom(href) ⇒ Object
ATOM feed link builder.
43 44 45 |
# File 'lib/murlsh/markup.rb', line 43 def atom(href) link :rel => 'alternate', :type => 'application/atom+xml', :href => href end |
#css(hrefs, options = {}) ⇒ Object
CSS link builder.
Options:
-
:media - optional media attribute
-
:prefix - prepended to all CSS urls
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/murlsh/markup.rb', line 52 def css(hrefs, ={}) ::Kernel::Array(hrefs).each do |href| attrs = { :href => "#{[:prefix]}#{href}", :rel => 'stylesheet', } attrs[:media] = [:media] if [:media] link attrs end end |
#form_input(options) ⇒ Object
Form input builder.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/murlsh/markup.rb', line 69 def form_input() if [:id] if [:label] label_class = [:required] ? 'required' : 'optional' label [:label], :for => [:id], :class => label_class end [:name] ||= [:id] end .delete :label [:type] ||= 'text' if %w{text password}.include?([:type]) and @req and not @req[[:name]].to_s.empty? [:value] = @req[[:name]] end input end |
#javascript(sources, options = {}) ⇒ Object
Javascript link builder. Takes list of script urls.
Options:
-
:prefix - prefix to append to all script urls
10 11 12 13 14 15 |
# File 'lib/murlsh/markup.rb', line 10 def javascript(sources, ={}) ::Kernel::Array(sources).each do |src| script '', :type => 'text/javascript', :src => "#{[:prefix]}#{src}" end end |
#metas(tags) ⇒ Object
Meta tag builder. Takes a hash of name => content.
64 65 66 |
# File 'lib/murlsh/markup.rb', line 64 def () .each { |k,v| :name => k, :content => v } end |
#murlsh_img(options = {}) ⇒ Object
Image tag builder.
Options:
-
:href - make the image a link to this url
-
:prefix - prefix to append to all image urls
-
:size - image size if square or [w, h]
-
:text - text for alt and title tag
Any other options in hash will be added as attributes.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/murlsh/markup.rb', line 26 def murlsh_img(={}) img_convert_prefix img_convert_size img_convert_text img_convert_data_uri if [:href] a(:href => [:href]) { .delete :href img } else img end end |