Module: Theme::Assets
- Defined in:
- lib/theme/assets.rb,
lib/theme/assets/render.rb,
lib/theme/assets/middleware.rb
Defined Under Namespace
Modules: Render
Classes: Middleware
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.compile ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/theme/assets.rb', line 48
def compile
Theme.config.assets.to_h.each do |type, assets|
content = ''
if assets.length > 0
type_path = "#{Theme.config.asset_path}/#{Theme.config[:"asset_#{type}_folder"]}"
assets.each do |file|
path = "#{type_path}/#{file}"
content += Theme.load_file path
end
tmp_path = "#{type_path}/tmp.theme-compiled.#{type}"
File.write tmp_path, content
system "minify #{tmp_path} > #{type_path}/theme-compiled-#{sha}.#{type}"
File.delete tmp_path
end
end
end
|
.css_assets(options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/theme/assets.rb', line 13
def css_assets options = {}
options = {
'data-turbolinks-track' => 'true',
rel: 'stylesheet',
type: 'text/css',
media: 'all'
}.merge options
url = Theme.config.asset_url
if Theme.config.assets_compiled
options[:href] = "#{url}/css/theme-compiled-#{sha}.css"
else
options[:href] = "#{url}/css/theme.css"
end
Theme.mab { link options }
end
|
.js_assets(options = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/theme/assets.rb', line 32
def js_assets options = {}
options = {
'data-turbolinks-track' => 'true',
}.merge options
url = Theme.config.asset_url
if Theme.config.assets_compiled
options[:src] = "#{url}/js/theme-compiled-#{sha}.js"
else
options[:src] = "#{url}/js/theme.js"
end
Theme.mab { script options }
end
|
.sha ⇒ Object
66
67
68
|
# File 'lib/theme/assets.rb', line 66
def sha
Thread.current[:_sha] ||= (Theme.config.sha || `git rev-parse HEAD`.strip)
end
|
Instance Method Details
#css_assets(options = {}) ⇒ Object
71
72
73
|
# File 'lib/theme/assets.rb', line 71
def css_assets options = {}
Theme::Assets.css_assets options
end
|
#js_assets(options = {}) ⇒ Object
75
76
77
|
# File 'lib/theme/assets.rb', line 75
def js_assets options = {}
Theme::Assets.js_assets options
end
|