stitch-rb 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,9 +13,8 @@ module Stitch
13
13
  Compiler.compilers.select {|c| c.enabled? }
14
14
  end
15
15
 
16
- def source_extensions
17
- compilers = all.select {|c| c.source? }
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 = #{content.to_json};
8
- module.exports = (function(view){ return Mustache.to_html(template, view); });}
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 = jQuery.template(#{content.to_json});
8
- module.exports = (function(data){ return jQuery.tmpl(template, data); });}
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
@@ -2,68 +2,66 @@ require "pathname"
2
2
 
3
3
  module Stitch
4
4
  class Source
5
- class << self
6
- # Recursively load all the sources from a given directory
7
- # Usage:
8
- # sources = Source.from_path("./app")
9
- #
10
- def from_path(root, path = nil, result = [])
11
- path ||= root
12
- path = Pathname.new(path)
13
-
14
- if path.directory?
15
- path.children.each do |child|
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
- result
17
+ else
18
+ source = self.new(root, path)
19
+ result << source if source.valid?
23
20
  end
21
+ result
22
+ end
24
23
 
25
- # Recursively resolve sources from a given file,
26
- # dynamically resolving its dependencies
27
- # Usage:
28
- # sources = Source.from_file("./app/index.js")
29
- #
30
- def from_file(root, path = nil, result = [])
31
- root = Pathname.new(root)
32
-
33
- unless path
34
- path = root
35
- root = root.dirname
36
- end
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
- result << source
37
+ source = self.new(root, path)
38
+ source.requires.each do |child|
39
+ from_file(root, child, result)
44
40
  end
45
41
 
46
- # Resolve a require call to an absolute path
47
- # Usage:
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
- unless path.absolute?
55
- path = path.expand_path(relative_to)
56
- end
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
- return path if path.exist?
53
+ unless path.absolute?
54
+ path = path.expand_path(relative_to)
55
+ end
59
56
 
60
- Compiler.source_extensions.each do |ext|
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
- raise "#{path} not found"
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
@@ -1,3 +1,3 @@
1
1
  module Stitch
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1 @@
1
+ {{name}}
@@ -26,7 +26,8 @@ class TestSource < Test::Unit::TestCase
26
26
  "app/index.js",
27
27
  "app/models/orm.js",
28
28
  "app/models/person.js",
29
- "app/models/user.js"
29
+ "app/models/user.js",
30
+ "app/views/index.mustache"
30
31
  ], sources
31
32
  end
32
33
 
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: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
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-07 00:00:00 -08:00
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