inline_view_component 0.2.0 → 0.3.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: 607417da7f98e59fe659b7226e82e8e346ec756e0a3d84fbe3e968c4f6f7cad7
4
- data.tar.gz: fd4e8c16b84f8da98cd0c21c29a8944e9c96763682b0e24a7e747f9c8cb20a83
3
+ metadata.gz: 241facae790b67960ece79f0801c24a0a697b9a333bd888a1d8ed3a8d4581624
4
+ data.tar.gz: c84f81173f4d29ed7a26e8b22c9c968860303a8d9f6ff3cee0383dbf9e82f18c
5
5
  SHA512:
6
- metadata.gz: 6580006c4280c2801cdacd9e2e824b8eb1f1085aef15529a997177d82c862ed6020b997d8b0f3b916229e89d292a7e94791b5ab928e7182fb447e93e25e6d286
7
- data.tar.gz: 27f66008ee2e7701848ca334b8c552ce5e0347ffd8c6a8b630fb8cdd40a5e01b9f234d5605bb68cdde75aa64f284b7413a440ce93049bee85f26848a2e4f4a95
6
+ metadata.gz: 05eacab78e40cb30bbf358a858548899ca8f3ab7a08d1e0172e851d61b76fbdb53595f594f6797e96c248f37215f85128a588474d4f0ffac30a9bf627512e7b0
7
+ data.tar.gz: b466c3dc4b82db5918451479f24fd183658bb401f858ab74682c4e00ebad9a4d66c690c4f66b9c54016642cb887966b447ed9057e6fc5965a7b984cf4bdd0c27
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # InlineViewComponent
2
- This gem allows your ViewComponents to define template strings within the class definition. ERB and HAML are supported. Syntax highlighting for Sublime Text is provided.
2
+
3
+ This gem allows your ViewComponents to define template strings within the class definition. You should be able to use any templating language your rails app supports (ERB, HAML, Slim...). There's also custom syntax highlighting for heredoc templates for Sublime Text.
3
4
 
4
5
  ## Usage
5
- Include the `InlineViewComponent` mixin and then specify your template string with `template(string)`. Be sure to delete your component's external template file or ViewComponent will raise an error.
6
+
7
+ Include the `InlineViewComponent` mixin and then specify your template string with `template(string)`. Be sure to delete your component's external template file or ViewComponent will raise an error.
6
8
 
7
9
  #### Examples
10
+
8
11
  ```ruby
9
12
  class ErbComponent < ViewComponent::Base
10
13
  include InlineViewComponent
@@ -28,13 +31,22 @@ class HamlComponent < ViewComponent::Base
28
31
  end
29
32
 
30
33
  self.inline_template_format = :haml
31
- template <<~Haml
34
+ template <<~HAML
32
35
  %p= message
33
- Haml
36
+ HAML
34
37
  end
35
38
  ```
36
39
 
40
+ You can also provide the template format as an optional second argument to the template method
41
+
42
+ ```ruby
43
+ template <<~SLIM, :slim
44
+ h1 Hello World!
45
+ SLIM
46
+ ```
47
+
37
48
  ## Installation
49
+
38
50
  Add this line to your application's Gemfile:
39
51
 
40
52
  ```ruby
@@ -42,37 +54,39 @@ gem 'inline_view_component'
42
54
  ```
43
55
 
44
56
  And then execute:
57
+
45
58
  ```bash
46
59
  $ bundle
47
60
  ```
48
61
 
49
62
  Or install it yourself as:
63
+
50
64
  ```bash
51
65
  $ gem install inline_view_component
52
66
  ```
53
67
 
54
68
  ## Syntax Highlighting
55
69
 
56
- Syntax highlighting for Sublime Text is available. Download (this file)[/editor/Ruby.sublime-syntax] and add it to your Sublime User package. Then open your ruby files in the `Ruby (Custom)` syntax (or choose `View -> Syntax -> Open All with current extention as...` to use it automatically).
70
+ Syntax highlighting for Sublime Text is available. Download [this file](/editor/Ruby.sublime-syntax) and add it to your Sublime User package. Then open your ruby files in the `Ruby (Custom)` syntax (or choose `View -> Syntax -> Open All with current extention as...` to use it automatically).
57
71
 
58
- To get syntax highlighting to work use `ERB` or `HAML` as the delimiter for your heredoc string e.g.
72
+ To get syntax highlighting to work use `ERB`, `HAML`, or `SLIM` as the delimiter for your heredoc string e.g.
59
73
 
60
74
  ```
61
- template <<~HAML
75
+ template <<~HAML, :haml
62
76
  %h1 A really great template
63
77
  HAML
64
78
  ```
65
79
 
66
80
  ## TODO
67
81
 
68
- This is an early release. Contributions are welcome!
82
+ This is an early release. Contributions are welcome!
69
83
 
70
- - [ ] better error reporting (all the info is there, but it could be clearer)
71
84
  - [ ] add syntax highlighting for more editors (VS Code, vim, ...)
72
- - [ ] add support for other templating languages (slim, ...)
73
85
 
74
86
  ## Contributing
87
+
75
88
  Send a pull request.
76
89
 
77
90
  ## License
91
+
78
92
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -14,8 +14,10 @@ module InlineViewComponent
14
14
  end
15
15
 
16
16
  # set the template for this component
17
- def self.template(template_string)
18
- format = inline_template_format || :erb
17
+ def self.template(template_string, format = nil)
18
+ if format.nil?
19
+ format = inline_template_format || :erb
20
+ end
19
21
 
20
22
  handler = ActionView::Template.handler_for_extension(format.to_s)
21
23
  @inline_template = if handler.method(:call).parameters.length > 1
@@ -24,9 +26,11 @@ module InlineViewComponent
24
26
  handler.call(OpenStruct.new(source: template_string, identifier: identifier, type: type))
25
27
  end
26
28
 
29
+ call_location = caller_locations(1, 1).first
30
+
27
31
  define_method :call do
28
32
  @output_buffer = ActionView::OutputBuffer.new
29
- raw instance_eval(self.class.inline_template)
33
+ raw instance_eval(self.class.inline_template, call_location.absolute_path, (call_location.lineno + 1))
30
34
  end
31
35
  end
32
36
  end
@@ -1,3 +1,3 @@
1
1
  module InlineViewComponent
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafe Rosen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-12 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: slim
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: standard
85
99
  requirement: !ruby/object:Gem::Requirement