html-native 0.2.4 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10608cfe99deda77bf919d12ed385dff6364260d596fbb672968c6ed708ca320
4
- data.tar.gz: 511d614f09a21a27506d25289a0f31f36d92864d1235eb2cc26f4c5008ac0aa8
3
+ metadata.gz: ed3076751962fc9a51ff463fbe86f2716fc06522f838def97ba375270ca81099
4
+ data.tar.gz: b03dca13fa0ff38781755ab1912cb3890fa8f2210b1cbb2bc9cb5de8f469a6fa
5
5
  SHA512:
6
- metadata.gz: 476f3e92ab73de39f6d05bf96fca229237e44de9e140f25f012e3556a04f61500dc85b8a5c216a1c799bf7db1b8cc14514f8ab65e48563813b6d98792b0964e2
7
- data.tar.gz: 804e56ce1f00a988bc5a590d13351ccd11175d1a7c7be64d7076a4c653ed8a868fb3bd0955da6251f32af161dfeabc3466930b2f8a4bdddc352ea88f1f3b60f6
6
+ metadata.gz: 3a55f9561c6e3cc998e3616bf685a0ff5700284bfe3a68c08cc1b9583e6f2daadd9c48cb7f448abf3479f16024f29906d6f3b70ca7a99289f566a2a1a02ed2e5
7
+ data.tar.gz: a184b3ddfe8cd71beb7fcb30b9ef460ca16ea9874c53b056b3ee67ffa9292c8ee6a4fb457a02d1f7b2640f0de4349a0e78fa6fbfe480ff2a43acbb49df2da416
data/lib/html-native.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require "html-native/constants"
2
2
  require "html-native/builder"
3
+ require "html-native/logic"
3
4
 
4
5
  module HTMLComponent
5
-
6
+
6
7
  # Generates generation methods for each HTML5-valid tag. These methods have the
7
8
  # name of the tag. Note that this interferes with the builtin `p` method.
8
9
  TAG_LIST.each do |tag|
@@ -17,6 +18,20 @@ module HTMLComponent
17
18
  end
18
19
  end
19
20
 
21
+ def doctype(type)
22
+ Builder.new("<!DOCTYPE #{type}>")
23
+ end
24
+
25
+ def _label(attrs = {}, &block)
26
+ attrs ||= {}
27
+ if block
28
+ body = block.call
29
+ Builder.new("<label#{attributes_list(:label, attrs)}>") + body + "</label>"
30
+ else
31
+ Builder.new("<label#{attributes_list(:label, attrs)}/>")
32
+ end
33
+ end
34
+
20
35
  # Creates a module that encompasses the given block in an HTMLComponent
21
36
  # context. This gives access to methods in the block as though the block was
22
37
  # declared as the `render` function in a module extending HTMLComponent
@@ -9,14 +9,14 @@ module HTMLComponent
9
9
  # the initial value.
10
10
  def initialize(strings = [])
11
11
  @strings = []
12
- @cache = case strings.class
13
- when Array
14
- strings.join
15
- when Enumerable
16
- strings.to_a.join
17
- else
18
- strings.to_s
19
- end
12
+ @cache =
13
+ if strings.kind_of? Array
14
+ strings.join
15
+ elsif strings.kind_of? Enumerable
16
+ strings.to_a.join
17
+ else
18
+ strings.to_s
19
+ end
20
20
  @cached = true
21
21
  end
22
22
 
@@ -17,7 +17,7 @@ module HTMLComponent
17
17
  :canvas, :noscript, :script,
18
18
  :del, :ins,
19
19
  :caption, :col, :colgroup, :table, :tbody, :td, :tfoot, :th, :thead, :tr,
20
- :button, :datalist, :fieldset, :form, :input, :label, :legend, :meter, :optgroup,
20
+ :button, :datalist, :fieldset, :form, :input, :legend, :meter, :optgroup,
21
21
  :option, :output, :progress, :select, :textarea,
22
22
  :details, :dialog, :menu, :summary,
23
23
  :slot, :template
@@ -0,0 +1,54 @@
1
+ module HTMLComponent
2
+ class Builder
3
+ define_method(:if) do |bool|
4
+ if bool
5
+ self
6
+ else
7
+ Builder.new
8
+ end
9
+ end
10
+
11
+ define_method(:unless) do |bool|
12
+ if bool
13
+ Builder.new
14
+ else
15
+ self
16
+ end
17
+ end
18
+ end
19
+
20
+ def _if(bool, &block)
21
+ if bool
22
+ Builder.new(block.call)
23
+ else
24
+ Builder.new
25
+ end
26
+ end
27
+
28
+ def _unless(bool, &block)
29
+ unless bool
30
+ Builder.new(block.call)
31
+ else
32
+ Builder.new
33
+ end
34
+ end
35
+ end
36
+
37
+ class String
38
+ define_method(:if) do |bool|
39
+ if bool
40
+ HTMLComponent::Builder.new(self)
41
+ else
42
+ HTMLComponent::Builder.new
43
+ end
44
+ end
45
+
46
+ define_method(:unless) do |bool|
47
+ # BAd form, purely for symmetry
48
+ unless bool
49
+ HTMLComponent::Builder.new(self)
50
+ else
51
+ HTMLComponent::Builder.new
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kellen Watt
@@ -20,6 +20,7 @@ files:
20
20
  - lib/html-native/builder.rb
21
21
  - lib/html-native/collections.rb
22
22
  - lib/html-native/constants.rb
23
+ - lib/html-native/logic.rb
23
24
  homepage: https://github.com/KellenWatt/html-native
24
25
  licenses:
25
26
  - MIT