Module: RubyView::Helpers::Tag

Included in:
Context
Defined in:
lib/rubyview/helpers/tag.rb

Instance Method Summary collapse

Instance Method Details

#divObject



6
# File 'lib/rubyview/helpers/tag.rb', line 6

def div(...); render_tag(:div, ...); end

#format_html_opts(**html_opts) ⇒ Object



31
32
33
34
35
# File 'lib/rubyview/helpers/tag.rb', line 31

def format_html_opts(**html_opts)
  return "" if html_opts.empty?
  _html = html_opts.map { |k, v| "#{k}='#{v}'" }.join(" ")
  " " + _html # Add initial space
end

#generate_tag(name, content = nil, **html_opts, &block) ⇒ Object

for assembling HTML tag



24
25
26
27
28
29
# File 'lib/rubyview/helpers/tag.rb', line 24

def generate_tag(name, content = nil, **html_opts, &block) # for assembling HTML tag
  content = block.call if block_given?
  self_closing = [:img].include?(name)
  end_content = "#{content}</#{name}>"
  "<#{name}#{format_html_opts(**html_opts)}#{"/" if self_closing}>#{end_content if !self_closing}"
end

#h1Object



4
# File 'lib/rubyview/helpers/tag.rb', line 4

def h1(...); render_tag(:h1, ...); end

#img(image_path, **html_opts) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/rubyview/helpers/tag.rb', line 7

def img(image_path, **html_opts)
  url_for_image = if defined?(Rails)
    ActionController::Base.helpers.asset_path(image_path)
  else
    image_path
  end
  render_tag(:img, nil, **html_opts.merge({src: url_for_image}))
end

#merge_classes(classes_1, classes_2) ⇒ Object



16
17
18
# File 'lib/rubyview/helpers/tag.rb', line 16

def merge_classes(classes_1, classes_2)
  (classes_1.split(" ") + classes_2.split(" ")).uniq
end

#pObject



5
# File 'lib/rubyview/helpers/tag.rb', line 5

def p(...); render_tag(:p, ...); end

#render_tagObject

for storing to rendered content variable.



20
21
22
# File 'lib/rubyview/helpers/tag.rb', line 20

def render_tag(...) # for storing to rendered content variable.
  @_rendered_content += generate_tag(...)
end