web_components_rails 1.1.2 → 1.2.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 +4 -4
- data/README.md +2 -0
- data/lib/web_components_rails/haml_template.rb +2 -0
- data/lib/web_components_rails/html_import_processor.rb +10 -4
- data/lib/web_components_rails/railtie.rb +10 -7
- data/lib/web_components_rails/version.rb +1 -1
- data/lib/web_components_rails.rb +1 -0
- metadata +38 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ee38d47a5c018dcae2fd5f839ceb482db80e1a3
|
4
|
+
data.tar.gz: 51dca8b201de7bd59a433d4a985013d553f3b8cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
[](https://travis-ci.org/uniite/web-components-rails)
|
5
|
+
|
4
6
|
## Usage
|
5
7
|
1. Include the gem in your Gemfile:
|
6
8
|
```ruby
|
@@ -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 = '
|
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
|
-
|
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 =
|
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 =
|
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 '
|
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.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
data/lib/web_components_rails.rb
CHANGED
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.
|
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-
|
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:
|
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
|