polymer-rails 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41a14ef2df4d8a7c32889b1f0a6673a4f7d4d4ac
4
- data.tar.gz: acf46614854b9ce11595c22cb12053f188f0486a
3
+ metadata.gz: eef638cd7e83a08318fd6df97fe5826a3bb4a84e
4
+ data.tar.gz: 6b7a005ea359b3e380e0580d9ca0c64029901e31
5
5
  SHA512:
6
- metadata.gz: f23e15005f90ea2ecbb028e16d88b6784cae92aaf1871b8d49759eb77a2ac676946a384d872ff36448c5c4d9720bf99b02a2b8d25a0d1e27e60fdb4cbea7c033
7
- data.tar.gz: be190c436f2265d78dd503350a6d27e995ba9f0cb0a267f6cad6d5dd22f6e8fc640e2758f61217a23dfe69691fe168b01714ae4f431687095aeddc12376a3053
6
+ metadata.gz: 17cc9af4f73200621d3fed91a29a70febdea309c4b54c102a0567a366f2690445880d1830d4debe866bc091e1f697d3136812e15b73cfa2f4c1ee363788777d9
7
+ data.tar.gz: 6ae629accb1778e8998c3479af457f15eb12800b925a2c2f89b026001eb7b2501a09be394ba5407b0e63a523e8e801a151d8198fa69067e6553007d683af5874
data/README.md CHANGED
@@ -10,9 +10,9 @@ Want to get started with [web components](http://www.w3.org/wiki/WebComponents/
10
10
  #### Prefer using SASS or CoffeeSript?
11
11
 
12
12
  Polymer-rails works well with compiling assets, such as CoffeeScript and Sass.
13
- You can easily use external stylesheet or script tag references in your web component with any extension that Sprockets recognize.
14
- Use `<link rel="stylesheet" href="application.sass">` for stylesheets and `<script src="application.coffee">` for javascripts.
13
+ You can easily use external stylesheet or script tag references in your web component `<link rel="stylesheet" href="application.css">` for stylesheets and `<script src="application.js">` for javascripts.
15
14
  This assets will be automatically compiled and required into component html file.
15
+ * Note that if you're using sass or coffe precompilation, assets are required to use '.css.sass' and '.js.coffee' extensions.*
16
16
 
17
17
 
18
18
 
@@ -36,7 +36,7 @@ Or install it yourself as:
36
36
 
37
37
  $ rails g polymer:install
38
38
 
39
- - This generator adds `//= require polymer/platform` into `application.js` manifest file
39
+ - This generator adds `//= require polymer/webcomponents` into `application.js` manifest file
40
40
  - Creates `app/assets/components` and `application.html` manifest file where you can include all your components.
41
41
  - Creates `vendor/assets/components` directory for third-party web components.
42
42
 
@@ -47,12 +47,12 @@ to import web components manifest to your app.
47
47
 
48
48
  $ rails g polymer:component <component-name>
49
49
 
50
- This generates new `<component-name>` component directory and .html file of the same name under `app/assets/components` folder.
50
+ This generates new `<component-name>` component directory and `.html`, `.css`, `.js` files of the same name under `app/assets/components` folder.
51
51
 
52
- Add your component to manifest file after requiring polymer:
52
+ Add your component to manifest file after requiring webcomponents:
53
53
 
54
54
  //
55
- //= require polymer/polymer
55
+ //= require polymer/webcomponents
56
56
  //= require component-name/component-name
57
57
 
58
58
  And you can use your component in Rails application!
@@ -4,13 +4,20 @@ module Polymer
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  def create_component_dir
7
- empty_directory "app/assets/components/#{file_name}"
7
+ empty_directory "app/assets/components/#{component_name}"
8
8
  end
9
9
 
10
10
  def copy_component_template
11
- template "component.html.erb", "app/assets/components/#{file_name}/#{file_name}.html"
11
+ template "component.html.erb", "app/assets/components/#{component_name}/#{component_name}.html"
12
+ template "component.js.erb", "app/assets/components/#{component_name}/#{component_name}.js"
13
+ template "component.css.erb", "app/assets/components/#{component_name}/#{component_name}.css"
12
14
  end
13
15
 
16
+ private
17
+
18
+ def component_name
19
+ name.gsub('_', '-').downcase
20
+ end
14
21
  end
15
22
  end
16
23
  end
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -1,15 +1,9 @@
1
- <polymer-element name="<%= name %>">
1
+ <polymer-element name="<%= component_name %>">
2
2
  <template>
3
- <style>
4
- :host {
5
- display: block;
6
- }
7
- </style>
3
+ <link rel="stylesheet" href="<%= component_name %>.css" />
8
4
 
9
5
  <h2><%= file_name.capitalize.gsub('_', ' ') %></h2>
10
6
  </template>
11
7
 
12
- <script type="text/javascript">
13
- Polymer('<%= name %>');
14
- </script>
8
+ <script src="<%= component_name %>.js"></script>
15
9
  </polymer-element>
@@ -0,0 +1,3 @@
1
+ Polymer('<%= component_name %>', {
2
+
3
+ });
@@ -20,7 +20,7 @@ module Polymer
20
20
 
21
21
  def require_imports
22
22
  @component.imports.each do |import|
23
- @context.require_asset component_path(import.attributes['href'].value)
23
+ @context.require_asset absolute_asset_path(import.attributes['href'].value)
24
24
  import.remove
25
25
  end
26
26
  end
@@ -38,19 +38,28 @@ module Polymer
38
38
  end
39
39
 
40
40
  def asset_content(file)
41
- dir = File.dirname(@context.pathname)
42
- path = File.absolute_path(file, dir)
43
- @context.evaluate path
41
+ asset_path = absolute_asset_path(file)
42
+ asset = find_asset(asset_path)
43
+ unless asset.blank?
44
+ @context.depend_on_asset asset_path
45
+ asset.to_s
46
+ else
47
+ nil
48
+ end
44
49
  end
45
50
 
46
- def component_path(file)
51
+ def absolute_asset_path(file)
47
52
  search_file = file.sub(/^(\.\.\/)+/, '/').sub(/^\/*/, '')
48
53
  ::Rails.application.assets.paths.each do |path|
49
54
  file_list = Dir.glob( "#{File.absolute_path search_file, path }*")
50
55
  return file_list.first unless file_list.blank?
51
56
  end
52
- component = File.absolute_path file, File.dirname(@context.pathname)
53
- return File.exists?(component) ? component : nil
57
+ components = Dir.glob("#{File.absolute_path file, File.dirname(@context.pathname)}*")
58
+ return components.blank? ? nil : components.first
59
+ end
60
+
61
+ def find_asset(asset_path)
62
+ ::Rails.application.assets.find_asset(asset_path)
54
63
  end
55
64
 
56
65
  end
@@ -1,5 +1,5 @@
1
1
  module Polymer
2
2
  module Rails
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polymer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaplinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-14 00:00:00.000000000 Z
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,7 +108,9 @@ files:
108
108
  - app/assets/javascripts/polymer/polymer.js
109
109
  - app/assets/javascripts/polymer/webcomponents.js
110
110
  - lib/generators/polymer/component/component_generator.rb
111
+ - lib/generators/polymer/component/templates/component.css.erb
111
112
  - lib/generators/polymer/component/templates/component.html.erb
113
+ - lib/generators/polymer/component/templates/component.js.erb
112
114
  - lib/generators/polymer/install/install_generator.rb
113
115
  - lib/generators/polymer/install/templates/application.html.erb
114
116
  - lib/generators/polymer/install/templates/bowerrc.json