web_components_rails 1.1.2 → 1.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
  SHA1:
3
- metadata.gz: a2c838515bccc724230aa2c257d7451f9a628bf0
4
- data.tar.gz: 2bb7ed75dc358bbb6fb4b7eb695bd540d1969389
3
+ metadata.gz: 8ee38d47a5c018dcae2fd5f839ceb482db80e1a3
4
+ data.tar.gz: 51dca8b201de7bd59a433d4a985013d553f3b8cb
5
5
  SHA512:
6
- metadata.gz: a1c77cb15af790c66d0e2288f9398d7d949185b8b6a5b2a800e6a254dc9c29031e576145e2fd77c5673b6be67660edd5e1f9182a1c7f7592735a3a3dc45e6c7f
7
- data.tar.gz: feee339559fc9d911304cdf69e4d5c6c9c5a6b9d3df6de0d9dda7cf63841460f82a9ebe7c2b30b8372413a9857308566f68c66a0678ef02d0c9af5ba0b44b2aa
6
+ metadata.gz: 9dd3ea1d1e48fae3242554412bfefcf59145e16156bda7f5b8b4da98858ce4c2e173463cbb6df4a5eb3c78509efcda1a4653780accd53fdd09f56bb572084a5f
7
+ data.tar.gz: 0e8f47aa490f05d8627e50ab0abd6a40496ea46217cbbcf5fe1c9d8de0d59d57fbe7f06c128b4e6712d5d00ca3e63d50467ddf19b8fb19c643cef0f48cdb2424
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # web_components_rails
2
2
  Ruby gem for using web components in Rails applications.
3
3
 
4
+ [![Build Status](https://travis-ci.org/uniite/web-components-rails.svg)](https://travis-ci.org/uniite/web-components-rails)
5
+
4
6
  ## Usage
5
7
  1. Include the gem in your Gemfile:
6
8
  ```ruby
@@ -1,3 +1,5 @@
1
+ require 'haml'
2
+
1
3
  class WebComponentsRails::HamlTemplate < Tilt::HamlTemplate
2
4
  def prepare
3
5
  @options = @options.merge(format: :html5)
@@ -6,7 +6,7 @@ require 'securerandom'
6
6
  # https://github.com/rails/sprockets/blob/3.x/lib/sprockets/directive_processor.rb
7
7
  class WebComponentsRails::HTMLImportProcessor
8
8
 
9
- VERSION = '8'
9
+ VERSION = '9'
10
10
 
11
11
  def self.instance
12
12
  @instance ||= new
@@ -27,7 +27,9 @@ class WebComponentsRails::HTMLImportProcessor
27
27
  end
28
28
 
29
29
  def call(input)
30
- @context = input[:environment].context_class.new(input)
30
+ # Sprockets::Environment for looking up assets, etc.
31
+ @environment = input[:environment]
32
+ @context = @environment.context_class.new(input)
31
33
  @data = input[:data]
32
34
  @filename = input[:filename]
33
35
  @dirname = File.dirname(@filename)
@@ -71,13 +73,15 @@ class WebComponentsRails::HTMLImportProcessor
71
73
  href_to_asset_path(href, base_dir)
72
74
  # CSS needs to be inlined
73
75
  when 'css', 'text/css'
74
- asset = ::Rails.application.assets.find_asset(path, accept: 'text/css')
76
+ asset = @environment.find_asset(path, accept: 'text/css')
75
77
  # Replace it inline with a style node containing the referenced CSS
76
78
  if asset
77
79
  style = Nokogiri::XML::Element.new('style', doc)
78
80
  style['original-href'] = href
79
81
  style.content = "\n" + asset.source
80
82
  link.replace(style)
83
+ # Let sprockets know we're dependent on this asset, so that the HTML gets re-compiled when the CSS changes
84
+ @context.depend_on_asset(path)
81
85
  end
82
86
  nil
83
87
  # Ignore unknown types
@@ -95,13 +99,15 @@ class WebComponentsRails::HTMLImportProcessor
95
99
  # which is already in the asset pipeline search path; fix those
96
100
  # (eg. from 'web_components/lib-a/foo.html', <script src='../lib-b/bar.js'> -> 'lib-b/bar.js')
97
101
  path = href_to_asset_path(src, base_dir)
98
- asset = ::Rails.application.assets.find_asset(path, accept: 'application/javascript')
102
+ asset = @environment.find_asset(path, accept: 'application/javascript')
99
103
  # Replace it with a script tag containing the referenced JS inline
100
104
  if asset
101
105
  new_script = Nokogiri::XML::Element.new('script', doc)
102
106
  new_script['original-src'] = src
103
107
  new_script.content = "\n" + asset.source
104
108
  script.replace(new_script)
109
+ # Let sprockets know we're dependent on this asset, so that the HTML gets re-compiled when the script changes
110
+ @context.depend_on_asset(path)
105
111
  end
106
112
  end
107
113
  end
@@ -1,4 +1,6 @@
1
- require 'haml'
1
+ require 'action_view'
2
+ require 'sprockets/railtie'
3
+
2
4
  class WebComponentsRails::Railtie < Rails::Railtie
3
5
  # Register our asset tag helpers
4
6
  initializer 'web_components.asset_tag_helper' do
@@ -15,11 +17,12 @@ class WebComponentsRails::Railtie < Rails::Railtie
15
17
 
16
18
  # Allows HAML templates to be used with asset pipeline
17
19
  initializer 'web_components.sprockets', after: 'sprockets.environment', group: :all do |app|
18
- app.assets.register_mime_type 'text/html', extensions: ['.html', '.haml']
19
- app.assets.register_preprocessor 'text/html', Sprockets::DirectiveProcessor
20
- app.assets.register_preprocessor 'text/html', WebComponentsRails::HTMLImportProcessor
21
- app.assets.register_engine '.haml', WebComponentsRails::HamlTemplate
22
- app.assets.register_bundle_processor 'text/html', ::Sprockets::Bundle
20
+ app.config.assets.configure do |env|
21
+ env.register_mime_type 'text/html', extensions: ['.html', '.haml']
22
+ env.register_preprocessor 'text/html', Sprockets::DirectiveProcessor
23
+ env.register_preprocessor 'text/html', WebComponentsRails::HTMLImportProcessor
24
+ env.register_engine '.haml', WebComponentsRails::HamlTemplate
25
+ env.register_bundle_processor 'text/html', ::Sprockets::Bundle
26
+ end
23
27
  end
24
28
  end
25
-
@@ -1,3 +1,3 @@
1
1
  module WebComponentsRails
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'nokogumbo'
2
+ require 'sprockets'
2
3
 
3
4
  module WebComponentsRails
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_components_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogumbo
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.4.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: railties
28
+ name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 4.0.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: sprockets
42
+ name: sprockets-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -52,6 +52,40 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '4.0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '3.0'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '4.0'
55
89
  description: Web components utils for rails
56
90
  email:
57
91
  - jon@jbotelho.com