skyrocket 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/skyrocket/asset.rb +14 -5
- data/lib/skyrocket/asset_dependency.rb +24 -0
- data/lib/skyrocket/asset_factory.rb +16 -3
- data/lib/skyrocket/asset_locator.rb +1 -1
- data/lib/skyrocket/asset_manager.rb +19 -9
- data/lib/skyrocket/asset_writer.rb +1 -1
- data/lib/skyrocket/coffeescript_processor.rb +2 -1
- data/lib/skyrocket/dependency_searcher.rb +17 -0
- data/lib/skyrocket/directive_processor.rb +13 -0
- data/lib/skyrocket/{asset_loader.rb → directive_reader.rb} +14 -15
- data/lib/skyrocket/empty_processor.rb +1 -2
- data/lib/skyrocket/erb_processor.rb +15 -7
- data/lib/skyrocket/errors.rb +1 -0
- data/lib/skyrocket/javascript_processor.rb +13 -0
- data/lib/skyrocket/less_processor.rb +1 -1
- data/lib/skyrocket/processor.rb +3 -2
- data/lib/skyrocket/processor_factory.rb +1 -1
- data/lib/skyrocket/version.rb +2 -2
- data/lib/skyrocket.rb +6 -0
- metadata +21 -17
data/lib/skyrocket/asset.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'digest/md5'
|
2
3
|
|
3
4
|
module Skyrocket
|
4
5
|
class Asset
|
@@ -15,15 +16,23 @@ module Skyrocket
|
|
15
16
|
@processor.post_process_name(@filename)
|
16
17
|
end
|
17
18
|
|
19
|
+
def to_s
|
20
|
+
name
|
21
|
+
end
|
22
|
+
|
18
23
|
def output_path
|
19
|
-
@output_dir + "/" +
|
24
|
+
@output_dir + "/" + output_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def output_name
|
28
|
+
digest = Digest::MD5.hexdigest(content)
|
29
|
+
ppn = @processor.post_process_name(@filename)
|
30
|
+
ext = File.extname(ppn)
|
31
|
+
"#{ppn.chomp(ext)}_#{digest}#{ext}"
|
20
32
|
end
|
21
33
|
|
22
34
|
def content
|
23
|
-
return @content
|
24
|
-
@content = raw
|
25
|
-
@content = @processor.process(@content) if @processor
|
26
|
-
return @content
|
35
|
+
return @content ||= @processor.process(raw, name)
|
27
36
|
end
|
28
37
|
|
29
38
|
def raw
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Skyrocket
|
2
|
+
class AssetDependency
|
3
|
+
attr_reader :asset
|
4
|
+
|
5
|
+
def initialize(asset, asset_factory)
|
6
|
+
@asset = asset
|
7
|
+
@af = asset_factory
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@asset.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def children
|
15
|
+
required = DirectiveReader.read_required(@asset)
|
16
|
+
required.map { |r| dep_from_name(r) }
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def dep_from_name(name)
|
21
|
+
AssetDependency.new(@af.from_name(name), @af)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -17,14 +17,27 @@ module Skyrocket
|
|
17
17
|
found = dir_search(name, @asset_dirs + @lib_dirs)
|
18
18
|
if found.length > 0
|
19
19
|
found.each do |file|
|
20
|
-
if @pf.post_process_name(file) =~ /#{name}$/
|
20
|
+
if @pf.post_process_name(file) =~ /#{name}$/ || file =~ /#{name}$/
|
21
21
|
dir, file = parts(file)
|
22
22
|
return Asset.new(dir, file, @output_dir, @pf.processor(file))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
raise AssetNotFoundError
|
27
|
+
raise AssetNotFoundError.new("Asset not found '#{name}'")
|
28
|
+
end
|
29
|
+
|
30
|
+
def name_exist?(name)
|
31
|
+
found = dir_search(name, @asset_dirs + @lib_dirs)
|
32
|
+
if found.length > 0
|
33
|
+
found.each do |file|
|
34
|
+
if @pf.post_process_name(file) =~ /#{name}$/ || file =~ /#{name}$/
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
return false
|
28
41
|
end
|
29
42
|
|
30
43
|
private
|
@@ -46,7 +59,7 @@ module Skyrocket
|
|
46
59
|
def dir_search(part, dirs)
|
47
60
|
found = Array.new
|
48
61
|
dirs.each do |dir|
|
49
|
-
found += Dir[dir + "/" + part + ".*"]
|
62
|
+
found += (Dir[dir + "/" + part] + Dir[dir + "/" + part + ".*"])
|
50
63
|
end
|
51
64
|
found
|
52
65
|
end
|
@@ -5,9 +5,9 @@ module Skyrocket
|
|
5
5
|
attr_reader :asset_dirs, :lib_dirs, :output_dir, :base_url, :style
|
6
6
|
|
7
7
|
def initialize(options)
|
8
|
-
@asset_dirs = options[:asset_dirs].map{ |ad|
|
9
|
-
@lib_dirs = options[:lib_dirs].map{ |ld|
|
10
|
-
@output_dir =
|
8
|
+
@asset_dirs = options[:asset_dirs].map{ |ad| File.expand_path(ad) }
|
9
|
+
@lib_dirs = options[:lib_dirs].map{ |ld| File.expand_path(ld) }
|
10
|
+
@output_dir = File.expand_path(options[:output_dir])
|
11
11
|
@base_url = options[:base_url]
|
12
12
|
@style = options[:style]
|
13
13
|
@af = AssetFactory.new(@asset_dirs, @lib_dirs, @output_dir)
|
@@ -25,13 +25,23 @@ module Skyrocket
|
|
25
25
|
gem 'listen', '>=0.4.2'
|
26
26
|
require 'listen'
|
27
27
|
|
28
|
-
|
28
|
+
begin
|
29
|
+
update_public(&block)
|
30
|
+
rescue Exception => e
|
31
|
+
puts e.message
|
32
|
+
puts e.backtrace
|
33
|
+
end
|
29
34
|
|
30
|
-
Listen.to(*(@asset_dirs
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
Listen.to(*(@asset_dirs)) do |modified, added, removed|
|
36
|
+
begin
|
37
|
+
(modified + added).each { |am| process_change(@af.build_asset(am), &block) }
|
38
|
+
removed.each do |del|
|
39
|
+
as = @af.build_asset(del)
|
40
|
+
process_deleted(as.output_path, &block)
|
41
|
+
end
|
42
|
+
rescue Exception => e
|
43
|
+
puts e.message
|
44
|
+
puts e.backtrace
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
@@ -3,10 +3,11 @@ require 'coffee-script'
|
|
3
3
|
module Skyrocket
|
4
4
|
class CoffeescriptProcessor
|
5
5
|
include Processor
|
6
|
+
include DirectiveProcessor
|
6
7
|
|
7
8
|
def extension; '.coffee'; end
|
8
9
|
|
9
|
-
def
|
10
|
+
def process_contents(contents, name)
|
10
11
|
CoffeeScript.compile(contents)
|
11
12
|
end
|
12
13
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Skyrocket
|
2
|
+
class DependencySearcher
|
3
|
+
def self.deps(node)
|
4
|
+
build_deps(node)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.build_deps(node, chain = Array.new)
|
8
|
+
results = Array.new
|
9
|
+
raise CircularReferenceError.new if chain.include?(node.name)
|
10
|
+
chain = chain.clone << node.name
|
11
|
+
node.children.each do |child|
|
12
|
+
results += build_deps(child, chain)
|
13
|
+
end
|
14
|
+
(results << node).uniq{ |n| n.name }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Skyrocket
|
2
|
+
module DirectiveProcessor
|
3
|
+
|
4
|
+
def preprocess_contents(contents, name)
|
5
|
+
asset = asset_factory.from_name(name)
|
6
|
+
start = AssetDependency.new(asset, asset_factory)
|
7
|
+
deps = DependencySearcher.deps(start)
|
8
|
+
deps.map do |r|
|
9
|
+
DirectiveReader.read_body(asset_factory.from_name(r.name))
|
10
|
+
end.join("\n")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,8 +1,5 @@
|
|
1
|
-
require 'shellwords'
|
2
|
-
|
3
|
-
# components of this file were borrowed from ruby sprokets, https://github.com/sstephenson/sprockets
|
4
1
|
module Skyrocket
|
5
|
-
class
|
2
|
+
class DirectiveReader
|
6
3
|
HEADER_PATTERN = /
|
7
4
|
\A (
|
8
5
|
(?m:\s*) (
|
@@ -13,28 +10,30 @@ module Skyrocket
|
|
13
10
|
)
|
14
11
|
)+
|
15
12
|
/x
|
16
|
-
|
13
|
+
|
17
14
|
DIRECTIVE_PATTERN = /
|
18
15
|
^ [\W]* = \s* (\w+.*?) (\*\/)? $
|
19
16
|
/x
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# Ensure body ends in a new line
|
28
|
-
@body += "\n" if @body != "" && @body !~ /\n\Z/m
|
18
|
+
def self.read_body(asset)
|
19
|
+
split_parts(asset)[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.read_required(asset)
|
23
|
+
split_parts(asset)[0]
|
29
24
|
end
|
30
25
|
|
31
|
-
def
|
32
|
-
|
26
|
+
def self.split_parts(asset)
|
27
|
+
raw = asset.raw
|
28
|
+
headers = raw[HEADER_PATTERN, 0].to_s.lines || [""]
|
29
|
+
body = $' || raw
|
30
|
+
headers = headers.each.map do |line|
|
33
31
|
if directive = line[DIRECTIVE_PATTERN, 1]
|
34
32
|
name, arg = Shellwords.shellwords(directive)
|
35
33
|
arg if name == 'require'
|
36
34
|
end
|
37
35
|
end.compact
|
36
|
+
[headers, body]
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -6,7 +6,7 @@ module Skyrocket
|
|
6
6
|
|
7
7
|
def extension; '.erb'; end
|
8
8
|
|
9
|
-
def
|
9
|
+
def process_contents(contents, name)
|
10
10
|
template = ERB.new(contents, nil, '-', '@out')
|
11
11
|
results = template.result(get_binding { |name=nil| '' })
|
12
12
|
if(@layout)
|
@@ -16,7 +16,7 @@ module Skyrocket
|
|
16
16
|
if name == nil
|
17
17
|
results
|
18
18
|
else
|
19
|
-
|
19
|
+
cf[name.to_sym] || ''
|
20
20
|
end
|
21
21
|
end)
|
22
22
|
end
|
@@ -40,7 +40,7 @@ module Skyrocket
|
|
40
40
|
"<script src=\"#{resolve(path)}\"></script>"
|
41
41
|
end
|
42
42
|
|
43
|
-
def link_to(content, path, options)
|
43
|
+
def link_to(content, path, options = Hash.new)
|
44
44
|
opt_s = to_opt_s(options)
|
45
45
|
"<a href=\"#{resolve(path)}\"#{opt_s}>#{content}</a>"
|
46
46
|
end
|
@@ -62,8 +62,7 @@ module Skyrocket
|
|
62
62
|
@out = ''
|
63
63
|
results = yield.chomp
|
64
64
|
@out = old
|
65
|
-
|
66
|
-
@content_for[key.to_sym] = results
|
65
|
+
cf[key.to_sym] = results
|
67
66
|
nil
|
68
67
|
end
|
69
68
|
|
@@ -76,7 +75,7 @@ module Skyrocket
|
|
76
75
|
if name == nil
|
77
76
|
results
|
78
77
|
else
|
79
|
-
|
78
|
+
cf[name.to_sym]
|
80
79
|
end
|
81
80
|
end)
|
82
81
|
@out = old
|
@@ -88,10 +87,19 @@ module Skyrocket
|
|
88
87
|
if(path.start_with?("/") || path =~ /^\w+:\/\//)
|
89
88
|
path
|
90
89
|
else
|
91
|
-
|
90
|
+
if asset_factory.name_exist?(path)
|
91
|
+
on = asset_factory.from_name(path).output_name
|
92
|
+
base_url == '/' ? "#{base_url}#{on}" : "#{base_url}/#{on}"
|
93
|
+
else
|
94
|
+
base_url == '/' ? "#{base_url}#{path}" : "#{base_url}/#{path}"
|
95
|
+
end
|
92
96
|
end
|
93
97
|
end
|
94
98
|
|
99
|
+
def cf
|
100
|
+
@content_for ||= Hash.new
|
101
|
+
end
|
102
|
+
|
95
103
|
def to_opt_s(options)
|
96
104
|
opt_s = options.keys.map{ |k| "#{k}=\"#{options[k]}\"" }.join(' ')
|
97
105
|
opt_s = " " + opt_s unless opt_s == ''
|
data/lib/skyrocket/errors.rb
CHANGED
data/lib/skyrocket/processor.rb
CHANGED
@@ -4,8 +4,9 @@ module Skyrocket
|
|
4
4
|
raise NotImplimentedError.new("must impliment #{caller[0][/`.*'/][1..-2]} for #{self.class.name}")
|
5
5
|
end
|
6
6
|
|
7
|
-
def process(contents)
|
8
|
-
|
7
|
+
def process(contents, name)
|
8
|
+
contents = preprocess_contents(contents, name) if self.respond_to?(:preprocess_contents)
|
9
|
+
process_contents(contents, name)
|
9
10
|
end
|
10
11
|
|
11
12
|
def process?(file)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Skyrocket
|
2
2
|
class ProcessorFactory
|
3
3
|
|
4
|
-
PROCESSORS = [ CoffeescriptProcessor, ErbProcessor, LessProcessor, EmptyProcessor ]
|
4
|
+
PROCESSORS = [ CoffeescriptProcessor, ErbProcessor, JavascriptProcessor, LessProcessor, EmptyProcessor ]
|
5
5
|
|
6
6
|
def process?(filename)
|
7
7
|
PROCESSORS.each do |processor|
|
data/lib/skyrocket/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Skyrocket
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/lib/skyrocket.rb
CHANGED
@@ -2,18 +2,24 @@ require 'skyrocket/version'
|
|
2
2
|
|
3
3
|
module Skyrocket
|
4
4
|
autoload :Asset, "skyrocket/asset"
|
5
|
+
autoload :AssetDependency, "skyrocket/asset_dependency"
|
5
6
|
autoload :AssetLocator, "skyrocket/asset_locator"
|
6
7
|
autoload :AssetFactory, "skyrocket/asset_factory"
|
7
8
|
autoload :AssetManager, "skyrocket/asset_manager"
|
8
9
|
autoload :AssetWriter, "skyrocket/asset_writer"
|
9
10
|
autoload :CoffeescriptProcessor, "skyrocket/coffeescript_processor"
|
11
|
+
autoload :DependencySearcher, "skyrocket/dependency_searcher"
|
12
|
+
autoload :DirectiveProcessor, "skyrocket/directive_processor"
|
13
|
+
autoload :DirectiveReader, "skyrocket/directive_reader"
|
10
14
|
autoload :EmptyProcessor, "skyrocket/empty_processor"
|
11
15
|
autoload :ErbProcessor, "skyrocket/erb_processor"
|
16
|
+
autoload :JavascriptProcessor, "skyrocket/javascript_processor"
|
12
17
|
autoload :LessProcessor, "skyrocket/less_processor"
|
13
18
|
autoload :Processor, "skyrocket/processor"
|
14
19
|
autoload :ProcessorFactory, "skyrocket/processor_factory"
|
15
20
|
|
16
21
|
autoload :AssetNotFoundError, "skyrocket/errors"
|
22
|
+
autoload :CircularReferenceError, "skyrocket/errors"
|
17
23
|
autoload :NoValidProcessorError, "skyrocket/errors"
|
18
24
|
autoload :PathNotInAssetsError, "skyrocket/errors"
|
19
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skyrocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: therubyracer
|
16
|
-
requirement: &
|
16
|
+
requirement: &70096236593860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70096236593860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: less
|
27
|
-
requirement: &
|
27
|
+
requirement: &70096236593440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70096236593440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: coffee-script
|
38
|
-
requirement: &
|
38
|
+
requirement: &70096236593020 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70096236593020
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack-test
|
49
|
-
requirement: &
|
49
|
+
requirement: &70096236592600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70096236592600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70096236592100 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '2.0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70096236592100
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
|
-
requirement: &
|
71
|
+
requirement: &70096236591680 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,11 +76,11 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70096236591680
|
80
80
|
description: An alternative and opinionated static content/ asset management tool
|
81
81
|
that will concatenate/ render javascript, coffeescript, css, less, erb and html
|
82
82
|
email:
|
83
|
-
- michael@
|
83
|
+
- michael.m.wasser@gmail.com
|
84
84
|
executables:
|
85
85
|
- skyrocket
|
86
86
|
extensions: []
|
@@ -89,25 +89,29 @@ files:
|
|
89
89
|
- README.md
|
90
90
|
- LICENSE
|
91
91
|
- lib/skyrocket/asset.rb
|
92
|
+
- lib/skyrocket/asset_dependency.rb
|
92
93
|
- lib/skyrocket/asset_factory.rb
|
93
|
-
- lib/skyrocket/asset_loader.rb
|
94
94
|
- lib/skyrocket/asset_locator.rb
|
95
95
|
- lib/skyrocket/asset_manager.rb
|
96
96
|
- lib/skyrocket/asset_writer.rb
|
97
97
|
- lib/skyrocket/cmd.rb
|
98
98
|
- lib/skyrocket/coffeescript_processor.rb
|
99
|
+
- lib/skyrocket/dependency_searcher.rb
|
99
100
|
- lib/skyrocket/dir_ext.rb
|
101
|
+
- lib/skyrocket/directive_processor.rb
|
102
|
+
- lib/skyrocket/directive_reader.rb
|
100
103
|
- lib/skyrocket/empty_processor.rb
|
101
104
|
- lib/skyrocket/erb_processor.rb
|
102
105
|
- lib/skyrocket/errors.rb
|
103
106
|
- lib/skyrocket/file_ext.rb
|
107
|
+
- lib/skyrocket/javascript_processor.rb
|
104
108
|
- lib/skyrocket/less_processor.rb
|
105
109
|
- lib/skyrocket/processor.rb
|
106
110
|
- lib/skyrocket/processor_factory.rb
|
107
111
|
- lib/skyrocket/version.rb
|
108
112
|
- lib/skyrocket.rb
|
109
113
|
- bin/skyrocket
|
110
|
-
homepage: http://www.
|
114
|
+
homepage: http://www.mikewasser.com/
|
111
115
|
licenses: []
|
112
116
|
post_install_message:
|
113
117
|
rdoc_options: []
|