Module: Murlsh::Markup

Included in:
UrlBody
Defined in:
lib/murlsh/markup.rb

Overview

Helper mixin for XML builder.

Instance Method Summary collapse

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, options={})
  ::Kernel::Array(hrefs).each do |href|
    attrs = {
      :href => "#{options[:prefix]}#{href}",
      :rel => 'stylesheet',
    }
    attrs[:media] = options[:media]  if options[: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(options)
  if options[:id]
    if options[:label]
      label_class = options[:required] ? 'required' : 'optional'
      label options[:label], :for => options[:id], :class => label_class
    end
    options[:name] ||= options[:id]
  end

  options.delete :label

  options[:type] ||= 'text'

  if %w{text password}.include?(options[:type]) and @req and
    not @req[options[:name]].to_s.empty?
    options[:value] = @req[options[:name]]
  end

  input options
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, options={})
  ::Kernel::Array(sources).each do |src|
    script '', :type => 'text/javascript',
      :src => "#{options[: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 metas(tags)
  tags.each { |k,v| meta :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(options={})
  img_convert_prefix options
  img_convert_size options
  img_convert_text options
  img_convert_data_uri options

  if options[:href]
    a(:href => options[:href]) {
      options.delete :href
      img options
    }
  else
    img options
  end
end