inline_view_component 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +78 -0
- data/Rakefile +27 -0
- data/lib/inline_view_component.rb +48 -0
- data/lib/inline_view_component/version.rb +3 -0
- data/lib/tasks/inline_view_component_tasks.rake +4 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4191985d37626a7ea9b3c078e5a835b06e97daa492c6c551ab644a75d5484979
|
4
|
+
data.tar.gz: 695f380d66ca4787e11a94bd3ec332d50db249b4483a8e1ab5fb4209d85fabae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1cc417a3e79d1012b62691e2778b63f247b57a1dbcb108769074e086acb0d349dc94bb6fd3b8dca03ad41ac182361eefc77394321d6c2915c429419a5fadd0f4
|
7
|
+
data.tar.gz: b1a185ed8a3e752b97e120dc0083561c9cf22ef812e1fb185ea5491b0300d327ba993380ee1991bdde4121a77c94d209780c9c4b749a89902ffbb6c1dfca54a1
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Rafe Rosen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
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.
|
3
|
+
|
4
|
+
## 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
|
+
#### Examples
|
8
|
+
```ruby
|
9
|
+
class ErbComponent < ViewComponent::Base
|
10
|
+
include InlineViewComponent
|
11
|
+
|
12
|
+
def message
|
13
|
+
"Such inline. Much convenient."
|
14
|
+
end
|
15
|
+
|
16
|
+
template <<~ERB
|
17
|
+
<p> <%= message %> </p>
|
18
|
+
ERB
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
class HamlComponent < ViewComponent::Base
|
24
|
+
include InlineViewComponent
|
25
|
+
|
26
|
+
def message
|
27
|
+
"Very HAML. Many terse."
|
28
|
+
end
|
29
|
+
|
30
|
+
self.inline_template_format = :haml
|
31
|
+
template <<~Haml
|
32
|
+
%p= message
|
33
|
+
Haml
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
Add this line to your application's Gemfile:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
gem 'inline_view_component'
|
42
|
+
```
|
43
|
+
|
44
|
+
And then execute:
|
45
|
+
```bash
|
46
|
+
$ bundle
|
47
|
+
```
|
48
|
+
|
49
|
+
Or install it yourself as:
|
50
|
+
```bash
|
51
|
+
$ gem install inline_view_component
|
52
|
+
```
|
53
|
+
|
54
|
+
## Syntax Highlighting
|
55
|
+
|
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).
|
57
|
+
|
58
|
+
To get syntax highlighting to work use `ERB` or `HAML` as the delimiter for your heredoc string e.g.
|
59
|
+
|
60
|
+
```
|
61
|
+
template <<~HAML
|
62
|
+
%h1 A really great template
|
63
|
+
HAML
|
64
|
+
```
|
65
|
+
|
66
|
+
## TODO
|
67
|
+
|
68
|
+
This is an early release. Contributions are welcome!
|
69
|
+
|
70
|
+
- [ ] better error reporting (all the info is there, but it could be clearer)
|
71
|
+
- [ ] add syntax highlighting for more editors (VS Code, vim, ...)
|
72
|
+
- [ ] add support for other templating languages (slim, ...)
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
Send a pull request.
|
76
|
+
|
77
|
+
## License
|
78
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'InlineViewComponent'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "tilt"
|
3
|
+
require "active_support/core_ext/string/output_safety"
|
4
|
+
|
5
|
+
module InlineViewComponent
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
FORMATS = [:erb, :haml].freeze
|
9
|
+
|
10
|
+
included do
|
11
|
+
class << self
|
12
|
+
attr_reader :inline_template, :inline_template_format
|
13
|
+
end
|
14
|
+
|
15
|
+
# set the template format for this component
|
16
|
+
def self.inline_template_format=(format)
|
17
|
+
unless InlineViewComponent::FORMATS.include? format
|
18
|
+
raise "unsupported format #{format}. Valid choices are: #{InlineViewComponent::FORMATS}"
|
19
|
+
end
|
20
|
+
|
21
|
+
@inline_template_format = format.to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
# set the template for this component
|
25
|
+
def self.template(template_string)
|
26
|
+
format = inline_template_format || :erb
|
27
|
+
|
28
|
+
@inline_template = InlineViewComponent::Compiler.compile_template(format, template_string)
|
29
|
+
|
30
|
+
define_method :call do
|
31
|
+
raw self.class.inline_template.render(self)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Compiler
|
37
|
+
def compile_template(format, template_string)
|
38
|
+
raise "unsupported format #{format}" unless InlineViewComponent::FORMATS.include?(format)
|
39
|
+
|
40
|
+
case format.to_sym
|
41
|
+
when :erb then Tilt::ErubiTemplate.new(nil, escape_html: true, escapefunc: "::ERB::Util::h") { template_string }
|
42
|
+
when :haml then Tilt["haml"].new(nil, 1, escape_html: true) { template_string }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module_function :compile_template
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inline_view_component
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rafe Rosen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: view_component
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tilt
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: haml-rails
|
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'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: standard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- rafe@hey.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- MIT-LICENSE
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- lib/inline_view_component.rb
|
122
|
+
- lib/inline_view_component/version.rb
|
123
|
+
- lib/tasks/inline_view_component_tasks.rake
|
124
|
+
homepage: http://github.com/existentialmutt/inline_view_component
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubygems_version: 3.1.2
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Include template strings in Rails ViewComponent class definitions
|
147
|
+
test_files: []
|