themeable 1.0.4 → 1.0.5

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: 5c2c88465cfcd7a507c2f118801ad8b5f707e568
4
- data.tar.gz: ec2e1826e7d404f8b3286fe9f1716255fe4e18b9
3
+ metadata.gz: db4bc5a365caaf437b4570e522968895ec67a6ff
4
+ data.tar.gz: 010b87b4f96cc921bd8bd9b9662f414b21dd72fa
5
5
  SHA512:
6
- metadata.gz: 9dbd7f95f31a7c182ba13214eb6658374ece3a4765922801d7efae104b876577ce5bfa98bf0ed05524646ea90d3f8931ed664b817329328de06a2cd04795c134
7
- data.tar.gz: 98f9b7da433ffdd4e7ff6c97336e9433e4c8ef30f3676f7562ffea1ee20a60c9b39613fdf1f89b356e1994762310386c67ecd2b365a9d0baa7b81798f9b5a984
6
+ metadata.gz: f392d1c3542e60a2cc72181bc72db2fd003ffef6f2bfb8af21b3db2e39f280faf0717d02874362c63199c738305594175776947e7eada7a0dad411e49c6f9608
7
+ data.tar.gz: 26019fbed804bba03dca79d1eae2444ec633db7c73f1a03206fa7f98668469c568d2b9a084c8643588ad8624b1697626d92c3684037c9d220cefe945c18d0080
@@ -36,6 +36,15 @@ module Themeable
36
36
  template 'generators/copy_assets_generator.rb', "lib/generators/theme_#{theme_name}/copy_assets_generator.rb"
37
37
  template 'generators/scaffold_generator.rb', "lib/generators/theme_#{theme_name}/scaffold_generator.rb"
38
38
 
39
+ # rakes
40
+ template 'resolve_css_path.rake', "lib/tasks/resolve_css_path.rake"
41
+ insert_into_file 'Rakefile', before: 'Bundler::GemHelper.install_tasks' do
42
+ <<-CODE
43
+ require '#{app_name}'
44
+ Dir.glob('lib/tasks/*.rake').each { |r| load r}
45
+ CODE
46
+ end
47
+
39
48
  # assets and views
40
49
  create_file "theme/assets/#{theme_name}/application.css"
41
50
  create_file "theme/assets/#{theme_name}/application.js"
@@ -0,0 +1,41 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ module Themeable
4
+ class CssPathResolver
5
+
6
+ attr_reader :theme
7
+ def initialize(theme)
8
+ @theme = theme
9
+ end
10
+
11
+ def resolve
12
+ root_directory = File.join(theme.root_path, 'vendor')
13
+ Dir["#{root_directory}/**/*.css"].each do |filename|
14
+ contents = File.read(filename) if FileTest.file?(filename)
15
+ # http://www.w3.org/TR/CSS2/syndata.html#uri
16
+ url_regex = /url\((?!\#)\s*['"]?((?![a-z]+:)([^'"\)]*?)([?#][^'"\)]*)?)['"]?\s*\)/
17
+
18
+ # Resolve paths in CSS file if it contains a url
19
+ if contents =~ url_regex
20
+ directory_path = Pathname.new(File.dirname(filename))
21
+ .relative_path_from(Pathname.new(root_directory))
22
+
23
+ # Replace relative paths in URLs with Rails asset_path helper
24
+ new_contents = contents.gsub(url_regex) do |match|
25
+ relative_path = $2
26
+ params = $3
27
+ image_path = directory_path.join(relative_path).cleanpath
28
+
29
+ "asset-url('#{image_path}#{params}')"
30
+ end
31
+
32
+ # Replace CSS with ERB CSS file with resolved asset paths
33
+ FileUtils.rm(filename)
34
+ File.write(filename.gsub(/css$/, 'scss'), new_contents)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ # ThemeColorAdmin::ResolveCssPath.new.resolve_css_paths('/Users/tao/projects/theme_color_admin/')
@@ -1,3 +1,3 @@
1
1
  module Themeable
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'themeable/css_path_resolver'
2
+
3
+ namespace :resolve do
4
+ desc "Resolve css paths from vendor"
5
+ task :css_path do
6
+ Themeable::CssPathResolver.new(Theme<%= theme_name.camelize %>).resolve
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themeable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - xiaohui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-08 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -69,12 +69,14 @@ files:
69
69
  - lib/themeable.rb
70
70
  - lib/themeable/acts_as_themeable.rb
71
71
  - lib/themeable/command.rb
72
+ - lib/themeable/css_path_resolver.rb
72
73
  - lib/themeable/railtie.rb
73
74
  - lib/themeable/theme.rb
74
75
  - lib/themeable/version.rb
75
76
  - templates/generators/copy_assets_generator.rb
76
77
  - templates/generators/copy_views_generator.rb
77
78
  - templates/generators/scaffold_generator.rb
79
+ - templates/resolve_css_path.rake
78
80
  - templates/theme_main.rb
79
81
  - templates/view_application.html.erb
80
82
  homepage: https://github.com/xiaohui-zhangxh/