html-native 0.2.3 → 0.3.2

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: 176be6b557435093c4163f66b0322073f986282895571dfd34fedceeb2b02ec8
4
- data.tar.gz: 836e4f3e0a94e1ea70da575b900f10fed0e4da232c87e0ac83f0eaa45b3612da
3
+ metadata.gz: c0f5b72fda7cb3ea69d2faeeb693995f9637d130c4fe420eaf2af485241ba1e3
4
+ data.tar.gz: c4cf23530a4dee5e13044668701ee4f8cd66f60a37bf80e357a74fb5fc107570
5
5
  SHA512:
6
- metadata.gz: 4346fd63e18a2187312c94b5d311467b1489c084ff23a80591aa726afe40a5ca5fb24aa160cb36f591eefb941fb8725b51c8a4d146d7b0ba82649edfdc475ba3
7
- data.tar.gz: 761266f6ea9dd4340dfd8287e94e21721b6411cbcf3f4a37ac6fade2a12bbb1c00af9bde691ada4292255157039ddb26118738644cb71f9ce51c1a3b85d20b47
6
+ metadata.gz: 8049b8dc8c076e6ea8b0850faa4fa1aa3bd2801e6a41c100fbbfef4c6410cd2a4717df2dd16c8f7e47d21d68452ae4c1db756b3b36786fed1f832f82b947b26d
7
+ data.tar.gz: bdc4844740e7fb6c3f491da49731a1bd2adfee5158a9ddaeb12988a2468070eac22358e3d866e61f377be7eaef1eb1e3e10bf58b952addef0f999a6dc9bb9cd3
data/lib/html-native.rb CHANGED
@@ -1,5 +1,6 @@
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
 
@@ -17,6 +18,10 @@ module HTMLComponent
17
18
  end
18
19
  end
19
20
 
21
+ def doctype(type)
22
+ Builder.new("<!DOCTYPE #{type}>")
23
+ end
24
+
20
25
  # Creates a module that encompasses the given block in an HTMLComponent
21
26
  # context. This gives access to methods in the block as though the block was
22
27
  # 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
 
@@ -57,7 +57,7 @@ module HTMLComponent
57
57
  @cache
58
58
  end
59
59
 
60
- alias to_str to_s
60
+ alias_method :to_str, :to_s
61
61
 
62
62
  # If the method does not exist on Builder, it is sent to String, by way
63
63
  # of the rendered Builder result. Modify-in-place methods will affect the
@@ -67,8 +67,8 @@ module HTMLComponent
67
67
  end
68
68
 
69
69
  # If String responds to the method, then Builder also responds to it.
70
- def respond_to_missing?(method)
71
- "".respond_to?(method)
70
+ def respond_to_missing?(method, include_all)
71
+ "".respond_to?(method, include_all)
72
72
  end
73
73
  end
74
74
  end
@@ -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.3
4
+ version: 0.3.2
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