Class: SparkEngine::Assets::Stylesheets
- Inherits:
-
AssetType
- Object
- AssetType
- SparkEngine::Assets::Stylesheets
show all
- Defined in:
- lib/spark_engine/plugin/assets/stylesheets.rb
Instance Attribute Summary
Attributes inherited from AssetType
#base, #plugin
Instance Method Summary
collapse
Methods inherited from AssetType
#build_failure, #build_success, #change, #compress, #destination, #file_event, #filter_files, #find_files, #find_node_module, #initialize, #local_path, #log_error, #log_success, #npm_command, #url, #urls, #watch
Instance Method Details
#asset_tag(*args) ⇒ Object
26
27
28
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 26
def asset_tag(*args)
stylesheet_link_tag(args)
end
|
#autoprefixer_config ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 15
def autoprefixer_config
@autoprefixer_config ||= begin
config_path = File.join( SparkEngine.plugin.root, 'config', 'autoprefixer.yml' )
if File.exist?( config_path )
YAML.load_file( config_path ).deep_symbolize_keys
else
{}
end
end
end
|
#build(ext = nil) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 30
def build(ext=nil)
files = find_files
files = files.reject {|f| !f.match(/\.#{ext}/) } if ext
files.each do |file|
begin
if File.extname(file).match(/\.css/)
build_css(file)
elsif File.extname(file).match(/\.s[ca]ss/)
build_sass(file)
end
puts build_success(file)
rescue Exception => e
build_failure file
if e.backtrace.is_a? Array
log_error "Error in file: #{local_path(e.backtrace[0])}"
end
log_error " #{e.message}\n" if e.message
end
end
end
|
#build_css(file) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 57
def build_css(file)
css = prefix( File.read(file) )
File.open(destination(file), 'w') { |io| io.write(css) }
compress(destination(file))
end
|
#build_sass(file) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 64
def build_sass(file)
style = SparkEngine.production? ? "compressed" : 'nested'
dest = destination(file)
Sass.logger.log_level = :error if SparkEngine.production?
css = prefix( Sass.compile_file(file, style: style) )
File.open(dest, 'w') { |io| io.write(css) }
compress(dest)
end
|
#data ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 85
def data
if @data
@data
else
data = {}
Dir[File.join(base, "**/*.yml")].each do |file|
key = file.sub(base+"/", '').sub(/^_/,'').sub('.yml','')
data[key] = SassParser.parse(file)
end
@data = data if SparkEngine.production?
data
end
end
|
#ext ⇒ Object
11
12
13
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 11
def ext
"*[ca]ss"
end
|
#prefix_css(css) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 77
def prefix_css(css)
if defined? AutoprefixerRails
AutoprefixerRails.process(css, autoprefixer_config).css
else
css
end
end
|
#versioned(file) ⇒ Object
103
104
105
|
# File 'lib/spark_engine/plugin/assets/stylesheets.rb', line 103
def versioned(file)
super(file.sub(/(\.css)?\.s[ca]ss$/i,'.css'))
end
|