silian-rail 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c111b502a1503228a57b19b429945ee20094d057
4
+ data.tar.gz: f3306d95bc03b98ad44b21d18bb87d0984ef62fc
5
+ SHA512:
6
+ metadata.gz: d1c1f820f779d2ed91910bd66bc1cf18b02b0009a306f49aed74bae3876ddf316e6754d36287f593ae1e5bddad8ac2c8c0d26d26bf0648a4ba11863c5c646a83
7
+ data.tar.gz: 9af698941183a93b38738ef9a108e93b53844bf5e8899728e140dd7b6fc2a488a7287d6f6a4a4ee44e8852a81e0f56bb1dfe54fb0c81452409c89bf2a16fffb0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Brandon Robins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # SilianRail
2
+
3
+ SilianRail extends [Sprockets](https://github.com/rails/sprockets) to allow you to import [Web Components](http://webcomponents.org/) into the [Rails Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html).
4
+
5
+ ## Installation
6
+
7
+ Add the following line to your Rails application's Gemfile:
8
+
9
+ gem 'silian-rail'
10
+
11
+ Run the bundle command:
12
+
13
+ $ bundle
14
+
15
+ And generate a manifest file by running:
16
+
17
+ $ rails generate silian_rail:install
18
+
19
+ The generator will create a components folder and manifest file at `app/assets/components/application.html`.
20
+
21
+ Finally, insert the following tag into your application layout:
22
+
23
+ <%= html_include_tag 'application' %>
24
+
25
+ ## Usage
26
+
27
+ Use the Sprockets [`require`](https://github.com/rails/sprockets#the-require-directive) Directive within the components manifest file to pull in a web component and its dependencies.
28
+
29
+ When referencing a web component (i.e. the Polymer [paper-card](https://elements.polymer-project.org/elements/paper-card) component) you must reference the actual HTML file like so:
30
+
31
+ *= require paper-card/paper-card
32
+
33
+ The require directive will search your assets paths (`app/assets`, `lib/assets`, and `vendor/assets` by default) for the directory and file. Once the directory/file is found, the component, along with any dependencies defined within, is pulled into the asset pipeline.
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( http://github.com/eanlain/silian-rail/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ module SilianRail
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc 'Copies a HTML manifest to app/assets/components/application.html'
7
+
8
+ def copy_component_manifest
9
+ copy_file 'component_manifest.html', 'app/assets/components/application.html'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ <!--
2
+ * This is a manifest file that'll be compiled into application.html, which will include all the files
3
+ * listed below and their dependencies.
4
+ *
5
+ * Any html files within this directory, lib/assets/*, or vendor/assets/*
6
+ * can be referenced here using a relative path.
7
+ *
8
+ * require web_component_directory/web_component_name
9
+ *
10
+ *
11
+ -->
@@ -0,0 +1,3 @@
1
+ require 'silian-rail/asset_helpers'
2
+ require 'silian-rail/railtie'
3
+ require 'silian-rail/version'
@@ -0,0 +1,54 @@
1
+ module ActionView
2
+ module Helpers
3
+ module AssetTagHelper
4
+ def html_include_tag(*sources)
5
+ options = sources.extract_options!.stringify_keys
6
+ integrity = compute_integrity?(options)
7
+
8
+ if options['debug'] != false && request_debug_assets?
9
+ sources.map { |source|
10
+ if asset = lookup_debug_asset(source, type: :html)
11
+ if asset.respond_to?(:to_a)
12
+ asset.to_a.map do |a|
13
+ construct_html_include_tag(path_to_html(a.logical_path, debug: true), options)
14
+ end
15
+ else
16
+ construct_html_include_tag(path_to_html(asset.logical_path, debug: true), options)
17
+ end
18
+ else
19
+ construct_html_include_tag(source, options)
20
+ end
21
+ }.flatten.uniq.join("\n").html_safe
22
+ else
23
+ sources.map { |source|
24
+ options = options.merge('integrity' => asset_integrity(source, type: :html)) if integrity
25
+ construct_html_include_tag source, options
26
+ }.join('\n').html_safe
27
+ end
28
+ end
29
+
30
+ def construct_html_include_tag(*sources)
31
+ options = sources.extract_options!.stringify_keys
32
+ path_options = options.extract!('protocol', 'extname', 'host').symbolize_keys
33
+ sources.uniq.map { |source|
34
+ tag_options = {
35
+ 'rel' => 'import',
36
+ 'href' => path_to_html(source, path_options)
37
+ }.merge!(options)
38
+ tag(:link, tag_options)
39
+ }.join("\n").html_safe
40
+ end
41
+ end
42
+
43
+ module AssetUrlHelper
44
+ ASSET_EXTENSIONS.merge!({ html: '.html' })
45
+ ASSET_PUBLIC_DIRECTORIES.merge!({ html: '/components' })
46
+
47
+ # Computes the path to a HTML asset in the public components directory.
48
+ def html_path(source, options = {})
49
+ path_to_asset(source, {type: :html}.merge!(options))
50
+ end
51
+ alias_method :path_to_html, :html_path # aliased to avoid conflicts with a html_path named route
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ module SilianRail
2
+ class PostProcessor
3
+ COMMENT_PATTERN = Regexp.new("<!---->|<!--[^\\[].*?-->", Regexp::MULTILINE | Regexp::IGNORECASE)
4
+
5
+ def initialize(context)
6
+ @context = context
7
+ @current_directory = File.dirname(context.pathname)
8
+ @import_assets = []
9
+
10
+ @remove_link_imports = Loofah::Scrubber.new do |node|
11
+ if (node.name == 'link') && (node['rel'] == 'import')
12
+ @import_assets.push get_asset_abs_path(node['href'])
13
+
14
+ node.remove
15
+ end
16
+ end
17
+ end
18
+
19
+ def call(data)
20
+ data = scrub_link_imports(data)
21
+ require_import_assets
22
+
23
+ data.to_s.gsub(COMMENT_PATTERN, '')
24
+ end
25
+
26
+ private
27
+
28
+ def get_asset_abs_path(relative_path)
29
+ File.absolute_path(relative_path, @current_directory)
30
+ end
31
+
32
+ def require_import_assets
33
+ @import_assets.each { |asset| @context.require_asset(asset) }
34
+ end
35
+
36
+ def scrub_link_imports(data)
37
+ Loofah.scrub_fragment(data, @remove_link_imports)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ module SilianRail
2
+ class Railtie < ::Rails::Railtie
3
+
4
+ config.assets.configure do |env|
5
+ require 'sprockets/directive_processor'
6
+ env.register_preprocessor 'text/html', Sprockets::DirectiveProcessor.new(
7
+ comments: [['<!--', '-->']]
8
+ )
9
+
10
+ require 'silian-rail/post_processor'
11
+ env.register_postprocessor 'text/html', :web_components do |context, data|
12
+ SilianRail::PostProcessor.new(context).call(data)
13
+ end
14
+
15
+ require 'sprockets/bundle'
16
+ env.register_bundle_processor 'text/html', Sprockets::Bundle
17
+
18
+ env.logger = Rails.logger
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SilianRail
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: silian-rail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Robins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-24 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: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: loofah
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description:
42
+ email: brandon.robins@onebnottwo.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - README.md
49
+ - lib/generators/silian_rail/install_generator.rb
50
+ - lib/generators/silian_rail/templates/component_manifest.html
51
+ - lib/silian-rail.rb
52
+ - lib/silian-rail/asset_helpers.rb
53
+ - lib/silian-rail/post_processor.rb
54
+ - lib/silian-rail/railtie.rb
55
+ - lib/silian-rail/version.rb
56
+ homepage: http://www.github.com/eanlain/silian-rail
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.5.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Use Web Components with the Rails Asset Pipeline
80
+ test_files: []