Module: EL::TagFactory

Included in:
E, AssetsMapper
Defined in:
lib/el/tag_factory.rb

Instance Method Summary collapse

Instance Method Details

#comment_tag(comment = nil) ⇒ Object



93
94
95
96
# File 'lib/el/tag_factory.rb', line 93

def comment_tag comment = nil
  comment = yield if block_given?
  '<!-- %s -->' % CGI.escapeHTML(comment.to_s)
end

#comment_tag!(comment = nil) ⇒ Object

same as ‘comment_tag` except it wont escape comment!



99
100
101
102
# File 'lib/el/tag_factory.rb', line 99

def comment_tag! comment = nil
  comment = yield if block_given?
  '<!-- %s -->' % comment
end

#css_tag(src, attrs = {}) ⇒ Object

shorthand for ‘link_tag` so you can type `css_tag “file”` instead of `link_tag rel: ’stylesheet’, href: “file.css”‘

URL are handled exactly as per ‘js_tag`



63
64
65
66
67
68
69
70
71
72
# File 'lib/el/tag_factory.rb', line 63

def css_tag src, attrs = {}
  src.is_a?(Hash) && (attrs = src) && (src = nil)
  src = src ? assets_url(src) : (attrs[:href] || attrs.delete(:src))
  suffix = attrs.delete(:suffix)
  attrs[:href] = '%s.css%s' % [src, suffix]
  attrs[:media] ||= 'all'
   attrs[:type] ||= 'text/css'
    attrs[:rel] ||= 'stylesheet'
  '<link%s>' % EUtils.html_tag_attrs(attrs)
end

#doctype_tag(&proc) ⇒ Object



89
90
91
# File 'lib/el/tag_factory.rb', line 89

def doctype_tag &proc
  "<!DOCTYPE html>\n%s" % (proc ? proc.call : '')
end

#js_tag(src, attrs = {}) ⇒ Object

shorthand for ‘script_tag` so you can type `js_tag “file”` instead of `script_tag type: ’text/javascript’, src: “file.js”‘

if URL given as first argument, it should not contain extension. also URL will be automatically modified if used within assets mapper.

to set an URL that wont be modified in any way, use :src option.



49
50
51
52
53
54
55
56
# File 'lib/el/tag_factory.rb', line 49

def js_tag src, attrs = {}
  src.is_a?(Hash) && (attrs = src) && (src = nil)
  src = src ? assets_url(src) : attrs[:src]
  suffix = attrs.delete(:suffix)
  attrs[:src] = '%s.js%s' % [src, suffix]
  attrs[:type] ||= 'text/javascript'
  '<script%s></script>' % EUtils.html_tag_attrs(attrs)
end