stitch-rb 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/stitch/compiler.rb +2 -3
- data/lib/stitch/compilers/mustache.rb +4 -2
- data/lib/stitch/compilers/tmpl.rb +4 -2
- data/lib/stitch/source.rb +49 -51
- data/lib/stitch/version.rb +1 -1
- data/test/fixtures/app/views/index.mustache +1 -0
- data/test/test_source.rb +2 -1
- metadata +6 -4
data/lib/stitch/compiler.rb
CHANGED
@@ -13,9 +13,8 @@ module Stitch
|
|
13
13
|
Compiler.compilers.select {|c| c.enabled? }
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
compilers.map {|c| c.extensions }.flatten
|
16
|
+
def all_extensions
|
17
|
+
Compiler.all.map {|c| c.extensions }.flatten
|
19
18
|
end
|
20
19
|
|
21
20
|
def for_extension(extension)
|
@@ -4,8 +4,10 @@ module Stitch
|
|
4
4
|
|
5
5
|
def compile(path)
|
6
6
|
content = File.read(path)
|
7
|
-
%{var template
|
8
|
-
module.exports =
|
7
|
+
%{var template = #{content.to_json};
|
8
|
+
module.exports = function(view){
|
9
|
+
return Mustache.to_html(template, view);
|
10
|
+
};}
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -4,8 +4,10 @@ module Stitch
|
|
4
4
|
|
5
5
|
def compile(path)
|
6
6
|
content = File.read(path)
|
7
|
-
%{var template
|
8
|
-
module.exports =
|
7
|
+
%{var template = jQuery.template(#{content.to_json});
|
8
|
+
module.exports = function(data){
|
9
|
+
return jQuery.tmpl(template, data);
|
10
|
+
};}
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/lib/stitch/source.rb
CHANGED
@@ -2,68 +2,66 @@ require "pathname"
|
|
2
2
|
|
3
3
|
module Stitch
|
4
4
|
class Source
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
from_path(root, child, result)
|
17
|
-
end
|
18
|
-
else
|
19
|
-
source = self.new(root, path)
|
20
|
-
result << source if source.valid?
|
5
|
+
# Recursively load all the sources from a given directory
|
6
|
+
# Usage:
|
7
|
+
# sources = Source.from_path("./app")
|
8
|
+
#
|
9
|
+
def self.from_path(root, path = nil, result = [])
|
10
|
+
path ||= root
|
11
|
+
path = Pathname.new(path)
|
12
|
+
|
13
|
+
if path.directory?
|
14
|
+
path.children.each do |child|
|
15
|
+
from_path(root, child, result)
|
21
16
|
end
|
22
|
-
|
17
|
+
else
|
18
|
+
source = self.new(root, path)
|
19
|
+
result << source if source.valid?
|
23
20
|
end
|
21
|
+
result
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
source = self.new(root, path)
|
39
|
-
source.requires.each do |child|
|
40
|
-
from_file(root, child, result)
|
41
|
-
end
|
24
|
+
# Recursively resolve sources from a given file,
|
25
|
+
# dynamically resolving its dependencies
|
26
|
+
# Usage:
|
27
|
+
# sources = Source.from_file("./app/index.js")
|
28
|
+
#
|
29
|
+
def self.from_file(root, path = nil, result = [])
|
30
|
+
root = Pathname.new(root)
|
31
|
+
|
32
|
+
unless path
|
33
|
+
path = root
|
34
|
+
root = root.dirname
|
35
|
+
end
|
42
36
|
|
43
|
-
|
37
|
+
source = self.new(root, path)
|
38
|
+
source.requires.each do |child|
|
39
|
+
from_file(root, child, result)
|
44
40
|
end
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
# path = Source.resolve("../index.js", "/my/file.js")
|
49
|
-
#
|
50
|
-
def resolve(path, relative_to)
|
51
|
-
path = Pathname.new(path)
|
52
|
-
relative_to = Pathname.new(relative_to)
|
42
|
+
result << source
|
43
|
+
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
45
|
+
# Resolve a require call to an absolute path
|
46
|
+
# Usage:
|
47
|
+
# path = Source.resolve("../index.js", "/my/file.js")
|
48
|
+
#
|
49
|
+
def self.resolve(path, relative_to)
|
50
|
+
path = Pathname.new(path)
|
51
|
+
relative_to = Pathname.new(relative_to)
|
57
52
|
|
58
|
-
|
53
|
+
unless path.absolute?
|
54
|
+
path = path.expand_path(relative_to)
|
55
|
+
end
|
59
56
|
|
60
|
-
|
61
|
-
candidate = Pathname.new(path.to_s + "." + ext)
|
62
|
-
return candidate if candidate.exist?
|
63
|
-
end
|
57
|
+
return path if path.exist?
|
64
58
|
|
65
|
-
|
59
|
+
Compiler.all_extensions.each do |ext|
|
60
|
+
candidate = Pathname.new(path.to_s + "." + ext)
|
61
|
+
return candidate if candidate.exist?
|
66
62
|
end
|
63
|
+
|
64
|
+
raise "#{path} not found"
|
67
65
|
end
|
68
66
|
|
69
67
|
attr_reader :root, :path
|
data/lib/stitch/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{{name}}
|
data/test/test_source.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stitch-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex MacCaw
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-08 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- test/fixtures/app/models/orm.js
|
60
60
|
- test/fixtures/app/models/person.js
|
61
61
|
- test/fixtures/app/models/user.js
|
62
|
+
- test/fixtures/app/views/index.mustache
|
62
63
|
- test/fixtures/lib/jquery.js
|
63
64
|
- test/fixtures/lib/lib.coffee
|
64
65
|
- test/jasmine/index.html
|
@@ -107,6 +108,7 @@ test_files:
|
|
107
108
|
- test/fixtures/app/models/orm.js
|
108
109
|
- test/fixtures/app/models/person.js
|
109
110
|
- test/fixtures/app/models/user.js
|
111
|
+
- test/fixtures/app/views/index.mustache
|
110
112
|
- test/fixtures/lib/jquery.js
|
111
113
|
- test/fixtures/lib/lib.coffee
|
112
114
|
- test/jasmine/index.html
|