Module: Crystal::BasicHtmlHelper

Defined in:
lib/crystal/html/view_helpers/basic_html_helper.rb

Constant Summary collapse

BOOLEAN_ATTRIBUTES =
%w(disabled readonly multiple checked autobuffer
autoplay controls loop selected hidden scoped async
defer reversed ismap seemless muted required
autofocus novalidate formnovalidate open).to_set

Instance Method Summary collapse

Instance Method Details

#authenticity_tokenObject

authenticity_token



13
# File 'lib/crystal/html/view_helpers/basic_html_helper.rb', line 13

def authenticity_token; workspace.request.session['authenticity_token'] end

#h(obj) ⇒ Object

Escape



62
# File 'lib/crystal/html/view_helpers/basic_html_helper.rb', line 62

def h obj; obj.to_s.html_escape end

#image_tag(src, opt = {}) ⇒ Object

Assets



29
30
31
32
# File 'lib/crystal/html/view_helpers/basic_html_helper.rb', line 29

def image_tag src, opt = {}
  opt[:src] = src
  tag :img, '', opt
end

#label_tag(name, text, options = {}) ⇒ Object

Common HTML tags



38
39
40
# File 'lib/crystal/html/view_helpers/basic_html_helper.rb', line 38

def label_tag name, text, options = {}
  tag :label, text, options.merge(:for => name)
end

JavaScript & StyleSheets



19
20
21
22
23
# File 'lib/crystal/html/view_helpers/basic_html_helper.rb', line 19

def stylesheet_link_tag *stylesheets
  Array(stylesheets).collect{|ssheet|
    tag :link, '', :href => "#{config && config.url_root!}#{ssheet}", :media => "screen", :rel => "stylesheet", :type => "text/css"
  }.join("\n")
end

#tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object

Special



46
47
48
49
50
51
52
53
54
55
# File 'lib/crystal/html/view_helpers/basic_html_helper.rb', line 46

def tag name, content_or_options_with_block = nil, options = nil, escape = true, &block      
  if block_given?
    options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
    content = capture(&block)
    concat "<#{name}#{tag_options(options)}>#{content}</#{name}>"
  else
    content = content_or_options_with_block
    "<#{name}#{tag_options(options)}>#{content}</#{name}>"
  end      
end