Class: CodeSync::SprocketsAdapter
- Inherits:
-
Object
- Object
- CodeSync::SprocketsAdapter
show all
- Defined in:
- lib/code_sync/sprockets_adapter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(sprockets, options = nil) ⇒ SprocketsAdapter
Returns a new instance of SprocketsAdapter.
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/code_sync/sprockets_adapter.rb', line 49
def initialize sprockets, options=nil
if options.nil? and sprockets.is_a?(Hash)
options = sprockets
sprockets = nil
end
@options = options
@env = options[:sprockets] || Sprockets::Environment.new(options[:root] ||= Dir.pwd())
append_asset_paths()
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
105
106
107
|
# File 'lib/code_sync/sprockets_adapter.rb', line 105
def method_missing meth, *args, &block
env.send(meth, *args, &block)
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
47
48
49
|
# File 'lib/code_sync/sprockets_adapter.rb', line 47
def env
@env
end
|
#options ⇒ Object
Returns the value of attribute options.
47
48
49
|
# File 'lib/code_sync/sprockets_adapter.rb', line 47
def options
@options
end
|
Instance Method Details
#compile(content, options = {}) ⇒ Object
81
82
83
|
# File 'lib/code_sync/sprockets_adapter.rb', line 81
def compile content, options={}
create_asset(content,options).to_s
end
|
#create_asset(content, options = {}) ⇒ Object
85
86
87
|
# File 'lib/code_sync/sprockets_adapter.rb', line 85
def create_asset content, options={}
TempAsset.create_from(content, options.merge(env: env))
end
|
#process_changes_to(assets = []) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/code_sync/sprockets_adapter.rb', line 62
def process_changes_to assets=[]
results = Array(assets).map do |path|
asset = env.find_asset(path)
asset && notification = {
asset_path: path,
digest_path:asset.digest_path,
name:asset.logical_path,
source: (asset.to_s rescue nil),
path: path,
content: IO.read(path)
}
end
Array(results)
end
|
#project_asset_directories ⇒ Object
89
90
91
|
# File 'lib/code_sync/sprockets_adapter.rb', line 89
def project_asset_directories
directories = env.paths.select {|path| path.include?(root) }
end
|
#project_assets ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/code_sync/sprockets_adapter.rb', line 93
def project_assets
files = project_asset_directories.inject([]) do |memo, path|
memo += Dir.glob("#{path}/**/*")
end
files.reject! {|path| path.match(/\.min\.js/) || path.match(/\-min\.js/) }
files.select! {|path| path.match(/\.jst|\.coffee|\.css|\.js/)}
files
end
|