ruht 0.0.2 → 0.1.0

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: ece4fd78ad56b8ff0f6b00a8c0a22363144cd20997b55b8543f975cf8796f602
4
- data.tar.gz: 13a3910f3870b83a720f8d337f374f7b6d1b4533246d13fe437586e1020a9a93
3
+ metadata.gz: 1bbac88061aa6e3ebe5a2d47de160c912f56950dff0cef628598605b464fb03d
4
+ data.tar.gz: fed1a9e6095c3cbf859d4826eb83d06460575f932f48c9e21e238b5593d1e2a1
5
5
  SHA512:
6
- metadata.gz: bf681db394cc68422b782e87ae56b994446f2190d3e32e617717733fc59e2f1a4991cad0931a87d118cc354eeca4175de6f2c3164037debc9263cbaa0049bcc2
7
- data.tar.gz: 8a46c0f1c586c92a89e99d11fcb458575d5a33d270b5048b72fbcd71d5e10133e59805500d11a0d0c6e22482ddde7a47ad81cee3bdea6796fd2ba0b1f9cb1dac
6
+ metadata.gz: 8e126b337abc85c74003a1d56041d6434aeb6b1130110e6b31f365da5f6ddb0ea53e43c2add8a1db40c4653fb6be647faa1f9b27585038e1383c2779c8054609
7
+ data.tar.gz: 59d058ab1bed600e50112eb45cde4dbc8559799b0b951c624af8cc1e1989da6ed5e19717f58ea5ba8fa236559dfefe8f9f40b16fa99d9f8b779f405be52cc6fa
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.2.1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.1.0] - 2023-02-10
2
+
3
+ - Capturing variables and methods from the scope
4
+
5
+ ## [0.0.2] - 2023-02-07
6
+
7
+ - Capture methods from closure
8
+ - Improve types coverage
9
+
1
10
  ## [0.0.1] - 2023-02-05
2
11
 
3
12
  - Initial release
13
+ - Basic HTML rendering
14
+ - Support all HTML tag names
data/CODE_OF_CONDUCT.md CHANGED
@@ -39,7 +39,10 @@ This Code of Conduct applies within all community spaces, and also applies when
39
39
 
40
40
  ## Enforcement
41
41
 
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
43
+ reported to the community leaders responsible for enforcement at
44
+ dmitry.barskov64@gmail.com. All complaints will be reviewed and investigated
45
+ promptly and fairly.
43
46
 
44
47
  All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
48
 
data/Gemfile CHANGED
@@ -18,3 +18,7 @@ end
18
18
  group :test do
19
19
  gem 'rspec', '~> 3.0'
20
20
  end
21
+
22
+ group :development, :test do
23
+ gem 'byebug'
24
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruht (0.0.2)
4
+ ruht (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -12,6 +12,7 @@ GEM
12
12
  minitest (>= 5.1)
13
13
  tzinfo (~> 2.0)
14
14
  ast (2.4.2)
15
+ byebug (11.1.3)
15
16
  concurrent-ruby (1.2.0)
16
17
  csv (3.2.6)
17
18
  diff-lcs (1.5.0)
@@ -101,6 +102,7 @@ PLATFORMS
101
102
  x86_64-linux
102
103
 
103
104
  DEPENDENCIES
105
+ byebug
104
106
  rake (~> 13.0)
105
107
  rspec (~> 3.0)
106
108
  rubocop (~> 1.44.1)
@@ -111,4 +113,4 @@ DEPENDENCIES
111
113
  typeprof
112
114
 
113
115
  BUNDLED WITH
114
- 2.4.1
116
+ 2.4.6
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ruht
4
+ # Delegates method calls to the object who created the given block.
5
+ module ClosureCapturing
6
+ def initialize(context)
7
+ @context = context
8
+ end
9
+
10
+ private
11
+
12
+ def method_missing(method_name, *args, &block)
13
+ return super unless respond_to_missing?(method_name)
14
+
15
+ @context.send(method_name, *args, &block)
16
+ end
17
+
18
+ def respond_to_missing?(method_name, include_all = false)
19
+ @context.respond_to?(method_name.to_sym, include_all)
20
+ end
21
+ end
22
+ end
data/lib/ruht/document.rb CHANGED
@@ -18,10 +18,14 @@ module Ruht
18
18
  # ...
19
19
  # </html>
20
20
  class Document
21
+ include ClosureCapturing
22
+
21
23
  def initialize(&child_block)
22
24
  @doctype = nil
23
25
  @html = nil
24
26
  @child_block = child_block
27
+
28
+ super(@child_block&.binding&.receiver)
25
29
  end
26
30
 
27
31
  def doctype(*args)
data/lib/ruht/element.rb CHANGED
@@ -21,7 +21,7 @@ module Ruht
21
21
 
22
22
  [
23
23
  "<#{opening_tag}>",
24
- children,
24
+ children.lines.map { " #{_1}" }.join,
25
25
  "<#{closing_tag}>"
26
26
  ].join("\n").strip
27
27
  end
data/lib/ruht/fragment.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ruht/closure_capturing'
3
4
  require 'ruht/tags'
4
5
 
5
6
  module Ruht
@@ -15,12 +16,14 @@ module Ruht
15
16
  # <p />
16
17
  # <a />
17
18
  class Fragment
19
+ include ClosureCapturing
18
20
  include Tags
19
21
 
20
22
  def initialize(&child_block)
21
23
  @children = []
22
24
  @evaluated = false
23
25
  @child_block = child_block
26
+ super(child_block&.binding&.receiver)
24
27
  end
25
28
 
26
29
  # Allows to render other fragments / elements inside
@@ -48,17 +51,5 @@ module Ruht
48
51
  object.is_a?(simple_class)
49
52
  end
50
53
  end
51
-
52
- def method_missing(method_name, *args, &block)
53
- return super unless respond_to_missing?(method_name, *args, &block)
54
-
55
- @child_block.binding.receiver.send(method_name, *args, &block)
56
- end
57
-
58
- def respond_to_missing?(method_name, *args)
59
- return false unless @child_block
60
-
61
- @child_block.binding.receiver.respond_to?(method_name)
62
- end
63
54
  end
64
55
  end
data/lib/ruht/tags.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'ruht/attributes'
4
+ require 'ruht/element'
5
+ require 'ruht/void_element'
6
+
3
7
  module Ruht
4
8
  # DSL magic here. Including this module will define methods for HTML tags.
5
9
  module Tags
@@ -36,10 +40,7 @@ module Ruht
36
40
  module ClassMethods
37
41
  def def_tag(tag_name)
38
42
  define_method(tag_name) do |*args, **kwargs, &block|
39
- require 'ruht/attributes'
40
43
  attributes = Ruht::Attributes.new(*args, **kwargs)
41
-
42
- require 'ruht/element'
43
44
  element = Ruht::Element.new(tag_name, attributes, &block)
44
45
  render!(element)
45
46
  end
@@ -47,10 +48,7 @@ module Ruht
47
48
 
48
49
  def def_void_tag(tag_name)
49
50
  define_method(tag_name) do |*args, **kwargs|
50
- require 'ruht/attributes'
51
51
  attributes = Ruht::Attributes.new(*args, **kwargs)
52
-
53
- require 'ruht/void_element'
54
52
  element = Ruht::VoidElement.new(tag_name, attributes)
55
53
  render!(element)
56
54
  end
data/lib/ruht/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruht
4
- VERSION = '0.0.2'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -0,0 +1,12 @@
1
+ module Ruht
2
+ module ClosureCapturing
3
+ @context: untyped
4
+
5
+ def initialize: (untyped closure) -> void
6
+
7
+ private
8
+
9
+ def method_missing: (Symbol method_name, *untyped args) -> untyped
10
+ def respond_to_missing?: (Symbol method_name, ?bool include_all) -> bool
11
+ end
12
+ end
@@ -1,14 +1,17 @@
1
1
  module Ruht
2
2
  class Fragment
3
3
  extend Tags::ClassMethods
4
+ include ClosureCapturing
4
5
  include Tags
5
6
 
6
7
  @children: Array[untyped]
7
8
  @evaluated: bool
8
9
  @child_block: (^(self) -> untyped | nil)
10
+ @context: untyped
9
11
 
10
- def initialize: () ?{ (self) -> untyped } -> void
11
- def render!: (String | Fragment | Element | Symbol child_node) -> void
12
+ def initialize: ?{ (self) -> untyped } -> void
13
+
14
+ def render!: (untyped child_node) -> Array[untyped]
12
15
  def to_s: -> String
13
16
 
14
17
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruht
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Barskov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruht lets you generate HTML using Ruby syntax
14
14
  email:
@@ -35,6 +35,7 @@ files:
35
35
  - lib/ruht/attributes/content_attribute.rb
36
36
  - lib/ruht/attributes/data_attributes.rb
37
37
  - lib/ruht/attributes/style_attribute.rb
38
+ - lib/ruht/closure_capturing.rb
38
39
  - lib/ruht/document.rb
39
40
  - lib/ruht/element.rb
40
41
  - lib/ruht/file.rb
@@ -51,6 +52,7 @@ files:
51
52
  - sig/ruht/attributes/content_attribute.rbs
52
53
  - sig/ruht/attributes/data_attributes.rbs
53
54
  - sig/ruht/attributes/style_attribute.rbs
55
+ - sig/ruht/closure_capturing.rbs
54
56
  - sig/ruht/document.rbs
55
57
  - sig/ruht/element.rbs
56
58
  - sig/ruht/file.rbs
@@ -83,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  - !ruby/object:Gem::Version
84
86
  version: '0'
85
87
  requirements: []
86
- rubygems_version: 3.4.1
88
+ rubygems_version: 3.4.6
87
89
  signing_key:
88
90
  specification_version: 4
89
91
  summary: DSL for building HTML written in Ruby