Module: HtmlSlice

Defined in:
lib/html_slice.rb,
lib/html_slice/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

TAGS =

HTML as a first-class citizen in ruby code Faster than ERB.

i[
  div
  title
  embed
  meta
  br
  a
  em
  b
  i
  ul
  ol
  li
  img
  table
  tbody
  thead
  tr
  th
  td
  form
  input
  button
  link
  h1
  h2
  h3
  h4
  h5
  h6
  hr
  span
  label
  iframe
  template
  main
  footer
  aside
  source
  section
  small
  script
  nav
  area
].freeze
EMPTY_TAGS =
i[
  area
  br
  embed
  hr
  img
  input
  link
  meta
  source
].freeze
DEFAULT_SLICE =
:default
VERSION =
"0.2.1"

Instance Method Summary collapse

Instance Method Details

#_(content) ⇒ Object



97
98
99
# File 'lib/html_slice.rb', line 97

def _(content)
  @html_slice[@html_slice_current_id] << content.to_s
end

#html_layout(html_slice_current_id = DEFAULT_SLICE, &block) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/html_slice.rb', line 71

def html_layout(html_slice_current_id = DEFAULT_SLICE, &block)
  html_slice(
    html_slice_current_id,
    wrap: ["<!DOCTYPE html><html>", "</html>"],
    &block
  )
end

#html_slice(html_slice_current_id = DEFAULT_SLICE, wrap: ["", ""], &block) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/html_slice.rb', line 79

def html_slice(html_slice_current_id = DEFAULT_SLICE, wrap: ["", ""], &block)
  @html_slice_current_id = html_slice_current_id
  if block
    @html_slice ||= {}
    @html_slice[@html_slice_current_id] = wrap[0].dup
    instance_eval(&block)
    @html_slice[@html_slice_current_id] << wrap[1]
  else
    @html_slice[@html_slice_current_id] || ""
  end
end

#tag(tag_name, *args, &block) ⇒ Object



101
102
103
104
# File 'lib/html_slice.rb', line 101

def tag(tag_name, *args, &block)
  content, attributes = parse_html_tag_arguments(args)
  generate_and_append_html_tag(tag_name, content, attributes, &block)
end