inline_view_component 0.1.0 → 0.2.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: 4191985d37626a7ea9b3c078e5a835b06e97daa492c6c551ab644a75d5484979
4
- data.tar.gz: 695f380d66ca4787e11a94bd3ec332d50db249b4483a8e1ab5fb4209d85fabae
3
+ metadata.gz: 607417da7f98e59fe659b7226e82e8e346ec756e0a3d84fbe3e968c4f6f7cad7
4
+ data.tar.gz: fd4e8c16b84f8da98cd0c21c29a8944e9c96763682b0e24a7e747f9c8cb20a83
5
5
  SHA512:
6
- metadata.gz: 1cc417a3e79d1012b62691e2778b63f247b57a1dbcb108769074e086acb0d349dc94bb6fd3b8dca03ad41ac182361eefc77394321d6c2915c429419a5fadd0f4
7
- data.tar.gz: b1a185ed8a3e752b97e120dc0083561c9cf22ef812e1fb185ea5491b0300d327ba993380ee1991bdde4121a77c94d209780c9c4b749a89902ffbb6c1dfca54a1
6
+ metadata.gz: 6580006c4280c2801cdacd9e2e824b8eb1f1085aef15529a997177d82c862ed6020b997d8b0f3b916229e89d292a7e94791b5ab928e7182fb447e93e25e6d286
7
+ data.tar.gz: 27f66008ee2e7701848ca334b8c552ce5e0347ffd8c6a8b630fb8cdd40a5e01b9f234d5605bb68cdde75aa64f284b7413a440ce93049bee85f26848a2e4f4a95
@@ -1,12 +1,8 @@
1
1
  require "active_support/concern"
2
- require "tilt"
3
- require "active_support/core_ext/string/output_safety"
4
2
 
5
3
  module InlineViewComponent
6
4
  extend ActiveSupport::Concern
7
5
 
8
- FORMATS = [:erb, :haml].freeze
9
-
10
6
  included do
11
7
  class << self
12
8
  attr_reader :inline_template, :inline_template_format
@@ -14,10 +10,6 @@ module InlineViewComponent
14
10
 
15
11
  # set the template format for this component
16
12
  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
13
  @inline_template_format = format.to_sym
22
14
  end
23
15
 
@@ -25,24 +17,17 @@ module InlineViewComponent
25
17
  def self.template(template_string)
26
18
  format = inline_template_format || :erb
27
19
 
28
- @inline_template = InlineViewComponent::Compiler.compile_template(format, template_string)
29
-
30
- define_method :call do
31
- raw self.class.inline_template.render(self)
20
+ handler = ActionView::Template.handler_for_extension(format.to_s)
21
+ @inline_template = if handler.method(:call).parameters.length > 1
22
+ handler.call(self, template_string)
23
+ else
24
+ handler.call(OpenStruct.new(source: template_string, identifier: identifier, type: type))
32
25
  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
26
 
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 }
27
+ define_method :call do
28
+ @output_buffer = ActionView::OutputBuffer.new
29
+ raw instance_eval(self.class.inline_template)
43
30
  end
44
31
  end
45
-
46
- module_function :compile_template
47
32
  end
48
33
  end
@@ -1,3 +1,3 @@
1
1
  module InlineViewComponent
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.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.1.0
4
+ version: 0.2.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-10-25 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
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
55
  - !ruby/object:Gem::Dependency
70
56
  name: pg
71
57
  requirement: !ruby/object:Gem::Requirement