Class: Zfben_libjs::Css
- Inherits:
-
Source
- Object
- Source
- Zfben_libjs::Css
show all
- Defined in:
- lib/zfben_libjs/support_source/css.rb
Constant Summary
collapse
- REGEXP_REMOTE_CSS =
/@import[^"]+"([^"]+)"\)?;?/
- REGEXP_REMOTE_IMAGE =
/url\("?'?([^'")]+)'?"?\)/
Instance Attribute Summary
Attributes inherited from Source
#compiled, #filepath, #minified, #options, #source
Instance Method Summary
collapse
Methods inherited from Source
#compile, #download!, #initialize, #minify, #name, #remote?, #type
Instance Method Details
#after_initialize ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/zfben_libjs/support_source/css.rb', line 6
def after_initialize
@options = @options.merge({ :syntax => :sass, :style => :compressed, :cache => false })
@images = []
if @remote_path || @filepath
remote_url = File.dirname(@remote_path || @filepath)
@source = import_remote_css @source, remote_url
@source = download_images! remote_url
end
end
|
#before_minify ⇒ Object
34
35
36
|
# File 'lib/zfben_libjs/support_source/css.rb', line 34
def before_minify
@minified = Sass::Engine.new(to_sass, @options).render
end
|
#change_images_url! ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/zfben_libjs/support_source/css.rb', line 38
def change_images_url!
version = Time.now.strftime('?%s')
@source = @source.partition_all(REGEXP_REMOTE_IMAGE).map{ |line|
if REGEXP_REMOTE_IMAGE =~ line
path = line.match(REGEXP_REMOTE_IMAGE)[1]
filename = File.basename(path)
path = File.join(@options['src/images'], filename)
if File.exists?(path)
url = @options['url/images'] + '/' + filename + version
line = 'url("' << url << '")'
end
end
line
}.join "\n"
end
|
#images ⇒ Object
18
19
20
|
# File 'lib/zfben_libjs/support_source/css.rb', line 18
def images
@images
end
|
#to_css ⇒ Object
22
23
24
|
# File 'lib/zfben_libjs/support_source/css.rb', line 22
def to_css
compile
end
|
#to_sass ⇒ Object
26
27
28
|
# File 'lib/zfben_libjs/support_source/css.rb', line 26
def to_sass
Sass::CSS.new(@source, @options).render(:sass)
end
|
#to_scss ⇒ Object
30
31
32
|
# File 'lib/zfben_libjs/support_source/css.rb', line 30
def to_scss
Sass::CSS.new(@source, @options).render(:scss)
end
|