module EL::TagFactory

Public Instance Methods

comment_tag(comment = nil) { || ... } click to toggle source
# 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) { || ... } click to toggle source

same as ‘comment_tag` except it wont escape comment!

# 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 = {}) click to toggle source

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`

# 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) click to toggle source
# File lib/el/tag_factory.rb, line 89
def doctype_tag &proc
  "<!DOCTYPE html>\n%s" % (proc ? proc.call : '')
end
js_tag(src, attrs = {}) click to toggle source

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.

# 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

Private Instance Methods

assets_url(src) click to toggle source

just a placeholder to work when used outside Espresso

# File lib/el/tag_factory.rb, line 107
def assets_url src
  src
end