themeable 1.0.4 → 1.0.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 +4 -4
- data/lib/themeable/command.rb +9 -0
- data/lib/themeable/css_path_resolver.rb +41 -0
- data/lib/themeable/version.rb +1 -1
- data/templates/resolve_css_path.rake +8 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db4bc5a365caaf437b4570e522968895ec67a6ff
|
4
|
+
data.tar.gz: 010b87b4f96cc921bd8bd9b9662f414b21dd72fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f392d1c3542e60a2cc72181bc72db2fd003ffef6f2bfb8af21b3db2e39f280faf0717d02874362c63199c738305594175776947e7eada7a0dad411e49c6f9608
|
7
|
+
data.tar.gz: 26019fbed804bba03dca79d1eae2444ec633db7c73f1a03206fa7f98668469c568d2b9a084c8643588ad8624b1697626d92c3684037c9d220cefe945c18d0080
|
data/lib/themeable/command.rb
CHANGED
@@ -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/')
|
data/lib/themeable/version.rb
CHANGED
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
|
+
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-
|
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/
|