spar 0.2.7 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +272 -1
- data/bin/spar +30 -1
- data/lib/spar.rb +128 -7
- data/lib/spar/assets/404.jpg +0 -0
- data/lib/spar/assets/500.jpg +0 -0
- data/lib/spar/cli.rb +75 -22
- data/lib/spar/compiled_asset.rb +90 -0
- data/lib/spar/compiler.rb +74 -0
- data/lib/spar/compressor.rb +18 -0
- data/lib/spar/deployers/cloudfront_deployer.rb +33 -0
- data/lib/spar/deployers/deployer.rb +26 -0
- data/lib/spar/deployers/local_deployer.rb +15 -0
- data/lib/spar/deployers/s3_deployer.rb +75 -0
- data/lib/spar/directive_processor.rb +36 -0
- data/lib/spar/exceptions.rb +330 -0
- data/lib/spar/generators/templates/{README → base/README} +0 -0
- data/lib/spar/generators/templates/base/config.yml +12 -0
- data/lib/spar/generators/templates/pages/haml/app/pages/index.html.haml +11 -0
- data/lib/spar/generators/templates/pages/html/app/pages/index.html +16 -0
- data/lib/spar/generators/templates/{app/assets/javascripts/javascript.js.coffee → scripts/coffee/app/javascripts/application.js.coffee} +6 -3
- data/lib/spar/generators/templates/scripts/js/app/javascripts/application.js +11 -0
- data/lib/spar/generators/templates/styles/css/app/stylesheets/application.css +18 -0
- data/lib/spar/generators/templates/{app/assets → styles/sass/app}/stylesheets/application.css.sass +8 -4
- data/lib/spar/helpers.rb +31 -102
- data/lib/spar/not_found.rb +64 -0
- data/lib/spar/rewrite.rb +29 -0
- data/lib/spar/static.rb +46 -0
- data/lib/spar/tasks.rb +8 -13
- data/lib/spar/version.rb +1 -1
- metadata +261 -66
- data/lib/spar/assets.rb +0 -78
- data/lib/spar/base.rb +0 -54
- data/lib/spar/css_compressor.rb +0 -17
- data/lib/spar/deployer.rb +0 -198
- data/lib/spar/generators/application.rb +0 -42
- data/lib/spar/generators/templates/Gemfile +0 -3
- data/lib/spar/generators/templates/Rakefile +0 -8
- data/lib/spar/generators/templates/app/views/index.haml +0 -7
- data/lib/spar/generators/templates/config.ru +0 -9
- data/lib/spar/generators/templates/config/application.rb +0 -12
- data/lib/spar/generators/templates/script/server +0 -1
- data/lib/spar/static_compiler.rb +0 -91
data/lib/spar/static_compiler.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'rack/test'
|
3
|
-
|
4
|
-
module Spar
|
5
|
-
class StaticCompiler
|
6
|
-
|
7
|
-
VIEW_PATH_SPLITER = /(.*)\/([^\/]+?)/
|
8
|
-
|
9
|
-
attr_accessor :app, :env, :asset_path, :paths
|
10
|
-
|
11
|
-
def self.load_tasks
|
12
|
-
Dir[File.expand_path('../tasks/spar.rake', __FILE__)].each { |ext| load ext }
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(app, options = {})
|
16
|
-
@app = app
|
17
|
-
@env = app.asset_env
|
18
|
-
@public_path = app.public_path
|
19
|
-
@asset_path = File.join(app.public_path, app.asset_prefix)
|
20
|
-
@paths = App.asset_precompile
|
21
|
-
@digest = app.asset_digest
|
22
|
-
@zip_files = options.delete(:zip_files) || /\.(?:css|html|js|svg|txt|xml)$/
|
23
|
-
@view_paths = app.precompile_view_paths || []
|
24
|
-
@digest_free_assets = app.digest_free_assets || []
|
25
|
-
end
|
26
|
-
|
27
|
-
def compile
|
28
|
-
manifest = {}
|
29
|
-
@env.each_logical_path do |logical_path|
|
30
|
-
next unless compile_path?(logical_path)
|
31
|
-
if asset = @env.find_asset(logical_path)
|
32
|
-
manifest[logical_path] = write_asset(asset)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
write_manifest(manifest)
|
36
|
-
browser = Rack::Test::Session.new(Rack::MockSession.new(@app))
|
37
|
-
@view_paths.each do |path|
|
38
|
-
browser.get(path)
|
39
|
-
write_view(path, browser.last_response.body)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def write_manifest(manifest)
|
44
|
-
FileUtils.mkdir_p(@asset_path)
|
45
|
-
File.open("#{@asset_path}/manifest.yml", 'wb') do |f|
|
46
|
-
YAML.dump(manifest, f)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def write_view(path, body)
|
51
|
-
path = File.join(@public_path,path)
|
52
|
-
FileUtils.mkdir_p path
|
53
|
-
File.open(File.join(path,"index.html"), 'wb') do |f|
|
54
|
-
f.write(body)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def write_asset(asset)
|
59
|
-
path_for(asset).tap do |path|
|
60
|
-
filename = File.join(asset_path, path)
|
61
|
-
FileUtils.mkdir_p File.dirname(filename)
|
62
|
-
asset.write_to(filename)
|
63
|
-
# Use "example.txtgz" instead of "example.txt.gz" for Safari gzip workaround.
|
64
|
-
asset.write_to("#{filename}gz") if filename.to_s =~ @zip_files
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def compile_path?(logical_path)
|
69
|
-
@paths.each do |path|
|
70
|
-
case path
|
71
|
-
when Regexp
|
72
|
-
return true if path.match(logical_path)
|
73
|
-
when Proc
|
74
|
-
return true if path.call(logical_path)
|
75
|
-
else
|
76
|
-
return true if File.fnmatch(path.to_s, logical_path)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
false
|
80
|
-
end
|
81
|
-
|
82
|
-
def path_for(asset)
|
83
|
-
@digest_free_assets.each do |digest_free_path|
|
84
|
-
if digest_free_path.match(asset.logical_path)
|
85
|
-
return asset.logical_path
|
86
|
-
end
|
87
|
-
end
|
88
|
-
@digest ? asset.digest_path : asset.logical_path
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|