Module: Ezframe::Ht

Defined in:
lib/ezframe/ht.rb

Defined Under Namespace

Classes: List, Ol, Table, Ul

Class Method Summary collapse

Class Method Details

.button(arg) ⇒ Object

buttonタグにはデフォルトでtype=button属性を付ける



89
90
91
92
93
94
95
# File 'lib/ezframe/ht.rb', line 89

def button(arg)
  arg[:tag] = "button"
  unless arg[:type]
    arg[:type] = "button"
  end
  wrap_tag(arg)
end

.icon(arg) ⇒ Object

materialize用のiconメソッド 引数が文字列だったら、それをname属性とする



78
79
80
81
82
83
84
85
86
# File 'lib/ezframe/ht.rb', line 78

def icon(arg)
  if arg.is_a?(Hash)
    h = arg.clone
    h[:tag] = "icon"
    return wrap_tag(h)
  elsif arg.is_a?(String)
    return { tag: "icon", wrap: true, name: arg }
  end
end

.multi_div(class_a, child) ⇒ Object



97
98
99
100
101
102
# File 'lib/ezframe/ht.rb', line 97

def multi_div(class_a, child)
  class_a.reverse.each do |klass|
    child = Ht.div(class: klass, child: child)
  end
  return child
end

.search(ht_h, opts) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ezframe/ht.rb', line 104

def search(ht_h, opts)
  @found ||= []
  if ht_h.is_a?(Hash)
    if opts[:tag] && ht_h[:tag] && ht_h[:tag] == opts[:tag]
      @found.push(ht_h)
    end
    if ht_h[:child]
      search(ht_h[:child], opts)
    end
  elsif ht_h.is_a?(Array)
    ht_h.map { |h| search(h, opts) }
  end
  return @found
end

.single_tag(ht_h = {}) ⇒ Object Also known as: br, hr, img, input



26
27
28
29
30
31
# File 'lib/ezframe/ht.rb', line 26

def single_tag(ht_h = {})
  ht_h[:tag] ||= __callee__.to_s
  raise "no tag" if ht_h[:tag] == "wrap_tag"
  raise "has child: #{ht_h.inspect}" if ht_h[:child]
  return ht_h
end

.wrap_tag(ht_h = {}) ⇒ Object Also known as: script, h1, h2, h3, h4, h5, h6, p, div, span, i, strong, ul, ol, li, table, thead, tbody, tr, th, td, a, form, select, option, textarea, label, fieldset, nav, footer, small, pre, iframe, checkbox, radio

メソッド名の名前のタグのhthashを生成



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ezframe/ht.rb', line 6

def wrap_tag(ht_h = {})
  return nil unless ht_h
  if ht_h.is_a?(String) || ht_h.is_a?(Array)
    h = { child: ht_h }
  elsif ht_h.is_a?(Hash)
    if ht_h[:tag] && !__callee__.to_s.index("wrap_tag")
      h = { child: ht_h }
    else
      h = ht_h.dup
    end
  else
    EzLog.info("[WARN] wrap_tag: unknown type: #{ht_h.inspect}")
    return nil
  end
  h[:tag] ||= __callee__.to_s
  h[:wrap] = true
  raise "no tag" if h[:tag] == "wrap_tag"
  return h
end