rux 1.0.0 → 1.0.1

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: 29ba86ed38eae6295a1f2f3a68df1b371589c72c24ef4827541e238bdc288f5d
4
- data.tar.gz: 4db5f89366ba6bb85ef4939f33e55e71aed68baa9cc437d347f4888e1bb2e772
3
+ metadata.gz: 37160ed3c69f6fd3ee0e3b4597db3c41f0244853233b02aae52ba8bda17da87f
4
+ data.tar.gz: 20291beda480bab76790dbc9c6c300badd673d5d100aa097ef68244620bec4a7
5
5
  SHA512:
6
- metadata.gz: b94c6b6b4b9a4d802c32135b6f47f12186428b54a3d94c74a4eb72e858c077f4f4a8548615cd07e58c1b4a20340bcaba8412789e22f0387819850f0026f41eec
7
- data.tar.gz: 5f37c06fe42d57e38dafa661f9f22c7a0dd180375afe36d4c4d98ed38f01d29c9668b1bf2e81fec19b05278bbabf081871c448944456cfe1f6045716e9d12ff9
6
+ metadata.gz: d9b6bbf7e49fdd07dd528a24e4c7ab496e29872a84024c1d011ce8026f0e003b0f941ede542728d44d0bd5d67dfa66ffcdd0658514c61a9e59580b86ce946f5e
7
+ data.tar.gz: f7f5611e56d78988a6a514f2ae38cfe54848e6e855cdd85d5143963424a4c566bb09cd723c835bd16dcd7470591f21295d75432ef05981b0994533bc0e951949
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 1.0.1
2
+ * Fix bug in default buffer implementation causing `TypeError`s when attempting to shovel in arrays.
3
+
4
+ ## 1.0.0
5
+ * Birthday!
data/README.md CHANGED
@@ -182,7 +182,7 @@ Translating rux code (Ruby + HTML tags) into Ruby code happens in three phases:
182
182
 
183
183
  In the parsing phase, the token stream is transformed into an intermediate representation of the code known as an abstract syntax tree, or AST. It's the parser's job to work out which tags are children of other tags, associate attributes with tags, etc.
184
184
 
185
- Finally it's time to generate Ruby code in the emitting phase. The rux gem makes use of the visitor pattern to walk over all the nodes in the AST and generate a big string of Ruby code. This big string is the final product that can be written to a file and executed by the Ruby interpreter.
185
+ Finally it's time to generate Ruby code in the emitting phase. The rux gem makes use of the visitor pattern and the excellent [unparser gem](https://github.com/mbj/unparser) to walk over all the nodes in the AST and generate a big string of Ruby code. This big string is the final product that can be written to a file and executed by the Ruby interpreter.
186
186
 
187
187
  ## Transpiling Rux to Ruby
188
188
 
data/lib/rux/buffer.rb CHANGED
@@ -4,8 +4,8 @@ module Rux
4
4
  @string = init_str.dup
5
5
  end
6
6
 
7
- def <<(str)
8
- @string << (str || '')
7
+ def <<(*obj)
8
+ @string << obj.join
9
9
  end
10
10
 
11
11
  def to_s
@@ -1,7 +1,8 @@
1
1
  module Rux
2
2
  class DefaultTagBuilder
3
3
  def call(tag_name, attributes = {})
4
- "<#{tag_name} #{serialize_attrs(attributes)}>" <<
4
+ attr_str = attributes.empty? ? '' : " #{serialize_attrs(attributes)}"
5
+ "<#{tag_name}#{attr_str}>" <<
5
6
  (block_given? ? Array(yield) : []).join <<
6
7
  "</#{tag_name}>"
7
8
  end
data/lib/rux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rux
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/rux.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.platform = Gem::Platform::RUBY
12
12
 
13
13
  s.add_dependency 'parser', '~> 3.0'
14
- s.add_dependency 'unparser', '~> 0.5'
14
+ s.add_dependency 'unparser', '~> 0.6'
15
15
 
16
16
  s.require_path = 'lib'
17
17
  s.executables << 'ruxc'
data/spec/parser_spec.rb CHANGED
@@ -152,6 +152,33 @@ describe Rux::Parser do
152
152
  RUBY
153
153
  end
154
154
 
155
+ it 'handles HTML tags inside ruby code' do
156
+ rux_code = <<~RUX
157
+ <div>
158
+ {5.times.map do
159
+ <p>What a {@thing}</p>
160
+ end}
161
+ </div>
162
+ RUX
163
+
164
+ expect(compile(rux_code)).to eq(<<~RUBY.strip)
165
+ Rux.tag("div") {
166
+ Rux.create_buffer.tap { |_rux_buf_,|
167
+ _rux_buf_ << " "
168
+ _rux_buf_ << 5.times.map {
169
+ Rux.tag("p") {
170
+ Rux.create_buffer.tap { |_rux_buf_,|
171
+ _rux_buf_ << "What a "
172
+ _rux_buf_ << @thing
173
+ }.to_s
174
+ }
175
+ }
176
+ _rux_buf_ << " "
177
+ }.to_s
178
+ }
179
+ RUBY
180
+ end
181
+
155
182
  it 'handles regular HTML tags' do
156
183
  expect(compile('<div>foo</div>')).to eq(<<~RUBY.strip)
157
184
  Rux.tag("div") {
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rux do
4
+ def render(rux_code)
5
+ ruby_code = Rux.to_ruby(rux_code)
6
+ ViewComponent::Base.new.instance_eval(ruby_code)
7
+ end
8
+
9
+ it 'handles a HTML tags inside ruby code' do
10
+ result = render(<<~RUBY)
11
+ <div>
12
+ {3.times.map do
13
+ <p>Welcome!</p>
14
+ end}
15
+ </div>
16
+ RUBY
17
+
18
+ expect(result).to eq("<div> <p>Welcome!</p><p>Welcome!</p><p>Welcome!</p> </div>")
19
+ end
20
+
21
+ it 'handles rux tags inside ruby code' do
22
+ result = render(<<~RUBY)
23
+ <div>
24
+ {3.times.map do
25
+ <TestComponent><p>Welcome!</p></TestComponent>
26
+ end}
27
+ </div>
28
+ RUBY
29
+
30
+ expect(result).to eq("<div> <p>Welcome!</p><p>Welcome!</p><p>Welcome!</p> </div>")
31
+ end
32
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,5 +2,23 @@ require 'rspec'
2
2
  require 'rux'
3
3
  require 'pry-byebug'
4
4
 
5
+ # a very basic implementation of the view_component lib
6
+ module ViewComponent
7
+ class Base
8
+ attr_accessor :content
9
+
10
+ def render(component, &block)
11
+ component.content = block.call
12
+ component.call
13
+ end
14
+ end
15
+ end
16
+
17
+ class TestComponent < ViewComponent::Base
18
+ def call
19
+ content
20
+ end
21
+ end
22
+
5
23
  RSpec.configure do |config|
6
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rux
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.5'
33
+ version: '0.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.5'
40
+ version: '0.6'
41
41
  description: A jsx-inspired way to write view components.
42
42
  email:
43
43
  - camertron@gmail.com
@@ -46,6 +46,7 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - CHANGELOG.md
49
50
  - Gemfile
50
51
  - LICENSE
51
52
  - README.md
@@ -76,6 +77,7 @@ files:
76
77
  - lib/rux/visitor.rb
77
78
  - rux.gemspec
78
79
  - spec/parser_spec.rb
80
+ - spec/render_spec.rb
79
81
  - spec/spec_helper.rb
80
82
  homepage: http://github.com/camertron/rux
81
83
  licenses: []