slimi 0.6.0 → 0.7.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: 12b1a25a767a9ca17da4d9d99cf520d857131cd9d28acaf73d18a7696354c694
4
- data.tar.gz: fee58aeb65387fd4846e74ce6885bb96e97dca9db3f2f95578693e20752249a6
3
+ metadata.gz: '09a450cbc4d4a536b55bee031d9b76345aee45e82d112563d83cdadc1476a82c'
4
+ data.tar.gz: 781931ba445275b0bc24157df457dde36e49f74b7c48afedcbfa8cb279c6a401
5
5
  SHA512:
6
- metadata.gz: d97004ce75686f701d0a27bb8ac200e56956d5556fe4dbc874e523870d4c0467ee6eba5d5a1d7e34fc6d792d6df17ec85df689a297e94be56d44dadd33902c66
7
- data.tar.gz: d719cc21f5288051ae6e7be83cb1f85e82000dc0e7345160d0087f3d61d9aab9a17ce45978437ceefa6d47ce063034022170e2062fd5404ee4182f245edf0792
6
+ metadata.gz: 3810040838f6d5eaf636326eaa4021edd62a810d508b41efe7f27a29702c444a783cd2f0bfbd9dedc535d52738bc2446c55df08e6a6e0acee3cb3743ae7798f8
7
+ data.tar.gz: 625e3d9bd3be61d376364388f6ef86f555fe9065a73d802e907fcb1a6238d4707d42a5d4597acc05794d6e46d4623ebb01007836b2b8bb5ae2884158e3d16ad1
data/.rubocop.yml CHANGED
@@ -24,12 +24,14 @@ RSpec/ImplicitSubject:
24
24
  RSpec/MultipleExpectations:
25
25
  Enabled: false
26
26
 
27
+ RSpec/MultipleMemoizedHelpers:
28
+ Enabled: false
29
+
27
30
  RSpec/NamedSubject:
28
31
  Enabled: false
29
32
 
30
33
  Security/Eval:
31
- Exclude:
32
- - 'spec/**/*.rb'
34
+ Enabled: false
33
35
 
34
36
  Style/Documentation:
35
37
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.7.0 - 2022-01-04
6
+
7
+ ### Added
8
+
9
+ - Add `slimi` executable.
10
+
11
+ ### Fixed
12
+
13
+ - Remove preceding white spaces from HTML comment.
14
+ - Fix bug that :generator option was not working.
15
+ - Fix bug that Ruby code in nested line can be problem on compilation.
16
+
5
17
  ## 0.6.0 - 2022-01-03
6
18
 
7
19
  ### Added
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slimi (0.6.0)
4
+ slimi (0.7.0)
5
5
  temple
6
+ thor
6
7
  tilt
7
8
 
8
9
  GEM
@@ -74,6 +75,7 @@ GEM
74
75
  rubocop (~> 1.19)
75
76
  ruby-progressbar (1.11.0)
76
77
  temple (0.8.2)
78
+ thor (1.1.0)
77
79
  tilt (2.0.10)
78
80
  tzinfo (2.0.4)
79
81
  concurrent-ruby (~> 1.0)
data/README.md CHANGED
@@ -15,12 +15,16 @@ It uses Slimi to apply `rubocop --auto-correct` to embedded Ruby codes in Slim t
15
15
 
16
16
  ## Usage
17
17
 
18
- Just replace `gem 'slim'` with `gem 'slimi'` in your application's Gemfile.
18
+ ### Rails
19
+
20
+ Add this line to your application's Gemfile.
19
21
 
20
22
  ```ruby
21
23
  gem 'slimi'
22
24
  ```
23
25
 
26
+ This will cause `app/views/**/*.slim` files to be rendered by Slimi.
27
+
24
28
  ## Compatibility
25
29
 
26
30
  - Line indicators
@@ -53,8 +57,11 @@ gem 'slimi'
53
57
  - [ ] Translator/I18n
54
58
  - [ ] Logic-less mode
55
59
  - [ ] Smart text mode
56
- - Etc.
57
- - [ ] CLI tools
60
+ - CLI
61
+ - [x] Convert Slim to Ruby
62
+ - [x] Convert Slim to HTML
63
+ - [x] Convert Slim to ERB
58
64
  - Slimi-only features
59
65
  - [x] Embedded Ruby code location
60
- - [x] annotate_rendered_view_with_filenames
66
+ - [x] Support for annotate_rendered_view_with_filenames
67
+ - [x] Convert Slim to Temple expression by CLI
data/exe/slimi ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
5
+ require 'slimi'
6
+
7
+ Slimi::Cli.start
data/lib/slimi/cli.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module Slimi
6
+ # Provide CLI features.
7
+ class Cli < ::Thor
8
+ desc 'compile', 'Convert Slim into Ruby'
9
+ def compile
10
+ slim = $stdin.read
11
+ ruby = Engine.new.call(slim)
12
+ puts ruby
13
+ end
14
+
15
+ desc 'erb', 'Convert Slim into ERB'
16
+ def erb
17
+ slim = $stdin.read
18
+ expression = ErbConverter.new.call(slim)
19
+ puts expression
20
+ end
21
+
22
+ desc 'parse', 'Convert Slim into Temple expression'
23
+ def parse
24
+ slim = $stdin.read
25
+ expression = Parser.new.call(slim)
26
+ pp expression
27
+ end
28
+
29
+ desc 'render', 'Convert Slim into HTML'
30
+ def render
31
+ slim = $stdin.read
32
+ ruby = Engine.new.call(slim)
33
+ result = eval(ruby)
34
+ puts result
35
+ end
36
+ end
37
+ end
data/lib/slimi/engine.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'temple'
4
4
 
5
5
  module Slimi
6
- # Convert Slim code into Ruby code.
6
+ # Convert Slim into Ruby.
7
7
  class Engine < ::Temple::Engine
8
8
  define_options(
9
9
  attr_quote: '"',
@@ -16,9 +16,9 @@ module Slimi
16
16
  )
17
17
 
18
18
  use Parser
19
- use Filters::Unposition
20
19
  use Filters::Embedded
21
20
  use Filters::Interpolation
21
+ use Filters::Unposition
22
22
  use Filters::DoInserter
23
23
  use Filters::EndInserter
24
24
  use Filters::Control
@@ -34,6 +34,6 @@ module Slimi
34
34
  filter :ControlFlow
35
35
  filter :MultiFlattener
36
36
  filter :StaticMerger
37
- generator :StringBuffer
37
+ use(:Generator) { options[:generator] }
38
38
  end
39
39
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slimi
4
+ # Convert Slim into ERB.
5
+ class ErbConverter < Engine
6
+ replace :StaticMerger, ::Temple::Filters::CodeMerger
7
+ replace :Generator, Temple::Generators::ERB
8
+ end
9
+ end
@@ -30,6 +30,14 @@ module Slimi
30
30
  [:slimi, :output, escape, code, compile(expression)]
31
31
  end
32
32
 
33
+ # @param [Integer] begin_
34
+ # @param [Integer] end_
35
+ # @param [Array] expression
36
+ # @return [Array]
37
+ def on_slimi_position(begin_, end_, expression)
38
+ [:slimi, :position, begin_, end_, compile(expression)]
39
+ end
40
+
33
41
  # @param [String] type
34
42
  # @param [Array] expression
35
43
  # @return [Array]
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tilt'
4
+
3
5
  module Slimi
4
6
  module Filters
5
7
  # @api private
data/lib/slimi/parser.rb CHANGED
@@ -332,7 +332,7 @@ module Slimi
332
332
 
333
333
  # @return [Boolean]
334
334
  def parse_html_comment
335
- if @scanner.skip(%r{/!})
335
+ if @scanner.skip(%r{/![ \t]*})
336
336
  text_block = parse_text_block
337
337
  text = [:slimi, :text, :verbatim, text_block]
338
338
  @stacks.last << [:html, :comment, text]
data/lib/slimi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slimi
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/slimi.rb CHANGED
@@ -3,7 +3,9 @@
3
3
  require_relative 'slimi/version'
4
4
 
5
5
  module Slimi
6
+ autoload :Cli, 'slimi/cli'
6
7
  autoload :Engine, 'slimi/engine'
8
+ autoload :ErbConverter, 'slimi/erb_converter'
7
9
  autoload :Errors, 'slimi/errors'
8
10
  autoload :Filters, 'slimi/filters'
9
11
  autoload :Parser, 'slimi/parser'
data/slimi.gemspec CHANGED
@@ -32,5 +32,6 @@ Gem::Specification.new do |spec|
32
32
  }
33
33
 
34
34
  spec.add_dependency 'temple'
35
+ spec.add_dependency 'thor'
35
36
  spec.add_dependency 'tilt'
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-02 00:00:00.000000000 Z
11
+ date: 2022-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: temple
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: tilt
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -41,7 +55,8 @@ dependencies:
41
55
  description:
42
56
  email:
43
57
  - r7kamura@gmail.com
44
- executables: []
58
+ executables:
59
+ - slimi
45
60
  extensions: []
46
61
  extra_rdoc_files: []
47
62
  files:
@@ -56,8 +71,11 @@ files:
56
71
  - Rakefile
57
72
  - bin/console
58
73
  - bin/setup
74
+ - exe/slimi
59
75
  - lib/slimi.rb
76
+ - lib/slimi/cli.rb
60
77
  - lib/slimi/engine.rb
78
+ - lib/slimi/erb_converter.rb
61
79
  - lib/slimi/errors.rb
62
80
  - lib/slimi/filters.rb
63
81
  - lib/slimi/filters/amble.rb