classy_assets 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/classy_assets.gemspec +1 -0
- data/lib/classy_assets/sass/script/functions.rb +21 -0
- data/lib/classy_assets/sprockets/sass_importer.rb +91 -0
- data/lib/classy_assets/version.rb +1 -1
- data/lib/classy_assets.rb +17 -3
- metadata +17 -2
- data/lib/classy_assets/sass_script_functions.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d46c96e739ac209aa3be084cb29edc50b128add9
|
4
|
+
data.tar.gz: aadd3440b39e892a6274140698bbe05324c8cf22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80185477cad1aadc5f8d472bae056b27a66454bf145c2604f5c987a39eabec5d9b40ebf4792e5cbdd59abd40d24ee197162e03a18260d3f7b733156f81f42817
|
7
|
+
data.tar.gz: 22d8aef7596fa473f83907f5092832e4757b5a8b392d2a67ea185f8cfc4999a3f5e66a9553724184af3df802253388472e177ccb58cca64258934d55c521f138
|
data/classy_assets.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.add_dependency 'uglifier'
|
26
26
|
gem.add_dependency 'yui-compressor'
|
27
27
|
gem.add_dependency 'sinatra'
|
28
|
+
gem.add_dependency 'escape_utils'
|
28
29
|
|
29
30
|
gem.add_development_dependency 'bundler', '~> 1.3'
|
30
31
|
gem.add_development_dependency 'rake'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'sass/script/functions'
|
4
|
+
|
5
|
+
module Sass::Script::Functions
|
6
|
+
def asset_path(source)
|
7
|
+
Sass::Script::String.new(ClassyAssets.asset_url_for(source.value), :string)
|
8
|
+
end
|
9
|
+
|
10
|
+
def asset_url(source)
|
11
|
+
Sass::Script::String.new(%Q{url("#{ClassyAssets.asset_url_for(source.value)}")}, :string)
|
12
|
+
end
|
13
|
+
|
14
|
+
def asset_data_uri(source)
|
15
|
+
Sass::Script::String.new(%Q{url("#{ClassyAssets.asset_data_uri_for(path.value)}")}, :string)
|
16
|
+
end
|
17
|
+
|
18
|
+
declare :asset_path, args: [:source]
|
19
|
+
declare :asset_url, args: [:source]
|
20
|
+
declare :asset_data_uri, args: [:source]
|
21
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'sprockets/sass_importer'
|
5
|
+
|
6
|
+
module Sprockets
|
7
|
+
class SassImporter < ::Sass::Importers::Filesystem
|
8
|
+
GLOB = /\*|\[.+\]/
|
9
|
+
|
10
|
+
attr_reader :context
|
11
|
+
private :context
|
12
|
+
|
13
|
+
def initialize(context, root)
|
14
|
+
@context = context
|
15
|
+
super root.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def extensions
|
19
|
+
{
|
20
|
+
'css' => :scss,
|
21
|
+
'css.erb' => :scss,
|
22
|
+
'scss.erb' => :scss,
|
23
|
+
'sass.erb' => :sass
|
24
|
+
}.merge!(super)
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(name, options = {})
|
28
|
+
return nil if name =~ GLOB # globs must be relative
|
29
|
+
engine_from_path(name, root, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_relative(name, base, options)
|
33
|
+
if name =~ GLOB
|
34
|
+
glob_imports(name, Pathname.new(base), options)
|
35
|
+
else
|
36
|
+
engine_from_path(name, File.dirname(base), options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def each_globbed_file(glob, base_pathname, options)
|
43
|
+
Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
|
44
|
+
next if filename == options[:filename]
|
45
|
+
yield filename if File.directory?(filename) || context.asset_requirable?(filename)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def glob_imports(glob, base_pathname, options)
|
50
|
+
contents = ""
|
51
|
+
each_globbed_file(glob, base_pathname.dirname, options) do |filename|
|
52
|
+
if File.directory?(filename)
|
53
|
+
context.depend_on(filename)
|
54
|
+
elsif context.asset_requirable?(filename)
|
55
|
+
context.depend_on(filename)
|
56
|
+
contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
return nil if contents.empty?
|
60
|
+
Sass::Engine.new(contents, options.merge(
|
61
|
+
filename: base_pathname.to_s,
|
62
|
+
importer: self,
|
63
|
+
syntax: :scss
|
64
|
+
))
|
65
|
+
end
|
66
|
+
|
67
|
+
def engine_from_path(name, dir, options)
|
68
|
+
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
|
69
|
+
return unless full_filename && File.readable?(full_filename)
|
70
|
+
|
71
|
+
engine = Sass::Engine.new(evaluate(full_filename), options.merge(
|
72
|
+
filename: full_filename,
|
73
|
+
importer: self,
|
74
|
+
syntax: syntax
|
75
|
+
))
|
76
|
+
|
77
|
+
if engine && (filename = engine.options[:filename])
|
78
|
+
@context.depend_on(filename)
|
79
|
+
end
|
80
|
+
|
81
|
+
engine
|
82
|
+
end
|
83
|
+
|
84
|
+
def evaluate(filename)
|
85
|
+
attributes = context.environment.attributes_for(filename)
|
86
|
+
processors = context.environment.preprocessors(attributes.content_type) +
|
87
|
+
attributes.engines.reverse - [Sprockets::ScssTemplate, Sprockets::SassTemplate]
|
88
|
+
context.evaluate(filename, processors: processors)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/classy_assets.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
# ensure these come first to avoid tilt warnings
|
3
4
|
require 'compass'
|
4
5
|
require 'sass'
|
5
6
|
require 'coffee_script'
|
6
|
-
|
7
|
+
|
8
|
+
# stdlib
|
9
|
+
require 'base64'
|
10
|
+
require 'escape_utils'
|
7
11
|
require 'sinatra/base'
|
12
|
+
require 'sprockets'
|
13
|
+
|
14
|
+
# classy assets components
|
8
15
|
require 'classy_assets/configuration'
|
9
|
-
require 'classy_assets/
|
16
|
+
require 'classy_assets/sass/script/functions'
|
17
|
+
require 'classy_assets/sprockets/sass_importer'
|
10
18
|
require 'classy_assets/version'
|
11
19
|
|
20
|
+
# Utility methods
|
12
21
|
module ClassyAssets
|
13
22
|
def self.asset_url_for(asset)
|
14
23
|
asset = Configuration.sprockets[asset].send(determine_path_type)
|
@@ -16,6 +25,12 @@ module ClassyAssets
|
|
16
25
|
"#{Configuration.asset_host}/#{Configuration.asset_prefix}/#{asset}#{debug}"
|
17
26
|
end
|
18
27
|
|
28
|
+
def self.asset_data_uri_for(asset)
|
29
|
+
asset = Configuration.sprockets[asset]
|
30
|
+
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
|
31
|
+
"data:#{asset.content_type};base64,#{EscapeUtils.escape_url(base64)}"
|
32
|
+
end
|
33
|
+
|
19
34
|
def self.asset_tag_from(sources, ext)
|
20
35
|
sources = [sources] unless sources.is_a? Array
|
21
36
|
sources.map do |source|
|
@@ -29,4 +44,3 @@ module ClassyAssets
|
|
29
44
|
(Configuration.asset_digest) ? :digest_path : :logical_path
|
30
45
|
end
|
31
46
|
end
|
32
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classy_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- StyleSeek Engineering
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: escape_utils
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: bundler
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,7 +184,8 @@ files:
|
|
170
184
|
- lib/classy_assets.rb
|
171
185
|
- lib/classy_assets/cli.rb
|
172
186
|
- lib/classy_assets/configuration.rb
|
173
|
-
- lib/classy_assets/
|
187
|
+
- lib/classy_assets/sass/script/functions.rb
|
188
|
+
- lib/classy_assets/sprockets/sass_importer.rb
|
174
189
|
- lib/classy_assets/tasks.rb
|
175
190
|
- lib/classy_assets/tasks/assets.rake
|
176
191
|
- lib/classy_assets/version.rb
|