ruht 0.0.1 → 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: 778e8a28e69f33686442343e199b4aa9fbe3f295008a9d3bcc16c743c03d9358
4
- data.tar.gz: 7fbb6762ef0e55c160b17542b4d872895c35f673488d3dd398ef69adf090a185
3
+ metadata.gz: 1bbac88061aa6e3ebe5a2d47de160c912f56950dff0cef628598605b464fb03d
4
+ data.tar.gz: fed1a9e6095c3cbf859d4826eb83d06460575f932f48c9e21e238b5593d1e2a1
5
5
  SHA512:
6
- metadata.gz: 12283a4a5a1a3ef88c7037bd143cd8842b46bdce0ca53ebadb5e55d1b7bf7a86879ff289c33e6469ee095651f7e6d16fd78cb8058818858b6db30fffe4bdc011
7
- data.tar.gz: 3b9143c7d17fe9ff91fb5f3e4e7e02fdb366c03687d190ee436a7aa132f04059da092975919b5a6b94a6e97c58c18ff7da6653160e3cd2a37b35bacf3e237e91
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.1)
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
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.1'
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,19 +1,25 @@
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
15
18
 
16
19
  def eval_children!: -> void
17
20
  def can_render?: (untyped object) -> bool
21
+
22
+ def method_missing: (Symbol method_name, *untyped args) -> untyped
23
+ def respond_to_missing?: (Symbol method_name, *untyped args) -> bool
18
24
  end
19
25
  end
data/sig/ruht/tags.rbs CHANGED
@@ -1,5 +1,8 @@
1
1
  module Ruht
2
2
  module Tags
3
+ TAG_NAMES: Array[Symbol]
4
+ VOID_TAG_NAMES: Array[Symbol]
5
+
3
6
  def render!: (untyped _element) -> void
4
7
  def self.included: (Module receiver) -> void
5
8
 
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.1
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-05 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