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属性を付ける



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

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

.icon(arg) ⇒ Object

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



67
68
69
70
71
72
73
74
75
# File 'lib/ezframe/ht.rb', line 67

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", name: arg }
  end
end

.multi_div(class_a, child) ⇒ Object



86
87
88
89
90
91
# File 'lib/ezframe/ht.rb', line 86

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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ezframe/ht.rb', line 97

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

.small_text(text) ⇒ Object



93
94
95
# File 'lib/ezframe/ht.rb', line 93

def small_text(text)
  return small(class: %w[teal-text], child: text)
end

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

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



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

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