barista 0.1.5 → 0.2.0
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/barista.gemspec +4 -3
- data/lib/barista.rb +22 -21
- data/lib/barista/compiler.rb +4 -0
- data/lib/barista/framework.rb +60 -0
- data/lib/barista/version.rb +2 -2
- metadata +6 -12
data/barista.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{barista}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-02}
|
13
13
|
s.description = %q{Automatically compiles app/scripts/*.coffee to javascript for rails awesomesauce.}
|
14
14
|
s.email = %q{sutto@sutto.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/barista.rb",
|
29
29
|
"lib/barista/compiler.rb",
|
30
30
|
"lib/barista/filter.rb",
|
31
|
+
"lib/barista/framework.rb",
|
31
32
|
"lib/barista/tasks/barista.rake",
|
32
33
|
"lib/barista/version.rb",
|
33
34
|
"lib/generators/barista_install/USAGE",
|
@@ -37,7 +38,7 @@ Gem::Specification.new do |s|
|
|
37
38
|
s.homepage = %q{http://github.com/Sutto/barista}
|
38
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
40
|
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.3.
|
41
|
+
s.rubygems_version = %q{1.3.5}
|
41
42
|
s.summary = %q{Transparent coffeescript support for rails 3}
|
42
43
|
|
43
44
|
if s.respond_to? :specification_version then
|
data/lib/barista.rb
CHANGED
@@ -3,8 +3,9 @@ require 'pathname'
|
|
3
3
|
|
4
4
|
module Barista
|
5
5
|
|
6
|
-
autoload :Compiler,
|
7
|
-
autoload :Filter,
|
6
|
+
autoload :Compiler, 'barista/compiler'
|
7
|
+
autoload :Filter, 'barista/filter'
|
8
|
+
autoload :Framework, 'barista/framework'
|
8
9
|
|
9
10
|
class << self
|
10
11
|
|
@@ -18,6 +19,7 @@ module Barista
|
|
18
19
|
|
19
20
|
def root=(value)
|
20
21
|
@root = Pathname(value.to_s)
|
22
|
+
Framework.default_framework = nil
|
21
23
|
end
|
22
24
|
|
23
25
|
def output_root
|
@@ -28,38 +30,37 @@ module Barista
|
|
28
30
|
@output_root = Pathname(value.to_s)
|
29
31
|
end
|
30
32
|
|
31
|
-
def render_path(path)
|
32
|
-
full_path = root.join("#{path.gsub(/(\A\/|\/\Z)/, '')}.coffee")
|
33
|
-
return unless full_path.exist? && full_path.readable?
|
34
|
-
Compiler.compile(full_path.read)
|
35
|
-
rescue SystemCallError
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
|
39
33
|
def compile_file!(file, force = false)
|
40
|
-
|
41
|
-
|
42
|
-
destination_path =
|
43
|
-
return unless force ||
|
44
|
-
|
34
|
+
origin_path, framework = Framework.full_path_for(file)
|
35
|
+
return if origin_path.blank?
|
36
|
+
destination_path = self.output_path_for(file)
|
37
|
+
return unless force || Compiler.dirty?(origin_path, destination_path)
|
38
|
+
debug "Compiling #{file} from framework '#{framework.name}'"
|
45
39
|
FileUtils.mkdir_p File.dirname(destination_path)
|
46
40
|
File.open(destination_path, "w+") do |f|
|
47
|
-
f.write Compiler.compile(File.read(
|
41
|
+
f.write Compiler.compile(File.read(origin_path))
|
48
42
|
end
|
49
43
|
true
|
50
44
|
rescue SystemCallError
|
51
45
|
false
|
52
46
|
end
|
53
47
|
|
54
|
-
def should_compile_file?(from, to)
|
55
|
-
File.exist?(from) && (!File.exist?(to) || File.mtime(to) < File.mtime(from))
|
56
|
-
end
|
57
|
-
|
58
48
|
def compile_all!(force = false)
|
59
|
-
|
49
|
+
debug "Compiling all coffeescripts"
|
50
|
+
Framework.exposed_coffeescripts.each do |coffeescript|
|
51
|
+
compile_file! coffeescript, force
|
52
|
+
end
|
60
53
|
true
|
61
54
|
end
|
62
55
|
|
56
|
+
def output_path_for(file)
|
57
|
+
output_root.join(file.to_s.gsub(/^\/+/, '')).to_s.gsub(/\.coffee$/, '.js')
|
58
|
+
end
|
59
|
+
|
60
|
+
def debug(message)
|
61
|
+
Rails.logger.debug "[Barista] #{message}" if defined?(Rails.logger) && Rails.logger
|
62
|
+
end
|
63
|
+
|
63
64
|
# By default, only add it in dev / test
|
64
65
|
def add_filter?
|
65
66
|
Rails.env.test? || Rails.env.development?
|
data/lib/barista/compiler.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Barista
|
2
|
+
class Framework
|
3
|
+
|
4
|
+
def self.default_framework
|
5
|
+
@default_framework ||= self.new("default", Barista.root)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.default_framework=(value)
|
9
|
+
@default_framework = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
[default_framework] + (@all ||= [])
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.exposed_coffeescripts
|
17
|
+
all.inject([]) do |collection, fw|
|
18
|
+
collection + fw.exposed_coffeescripts
|
19
|
+
end.uniq
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.full_path_for(script)
|
23
|
+
script = script.to_s.gsub(/\.js$/, '.coffee').gsub(/^\/+/, '')
|
24
|
+
all.each do |fw|
|
25
|
+
full_path = fw.full_path_for(script)
|
26
|
+
return full_path, fw if full_path
|
27
|
+
end
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.register(name, root)
|
32
|
+
(@all ||= []) << self.new(name, root)
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :name, :framework_root
|
36
|
+
|
37
|
+
def initialize(name, root)
|
38
|
+
@name = name
|
39
|
+
@framework_root = File.expand_path(root)
|
40
|
+
end
|
41
|
+
|
42
|
+
def coffeescripts
|
43
|
+
Dir[File.join(@framework_root, "**", "*.coffee")]
|
44
|
+
end
|
45
|
+
|
46
|
+
def short_name(script)
|
47
|
+
File.expand_path(script).gsub /^#{Regexp.escape(@framework_root)}\/?/, ''
|
48
|
+
end
|
49
|
+
|
50
|
+
def exposed_coffeescripts
|
51
|
+
coffeescripts.map { |script| short_name(script) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def full_path_for(name)
|
55
|
+
full_path = File.join(@framework_root, name)
|
56
|
+
File.exist?(full_path) ? full_path : nil
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
data/lib/barista/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barista
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
version: 0.1.5
|
4
|
+
version: 0.2.0
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Darcy Laycock
|
@@ -14,7 +9,7 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-
|
12
|
+
date: 2010-05-02 00:00:00 +08:00
|
18
13
|
default_executable:
|
19
14
|
dependencies: []
|
20
15
|
|
@@ -39,6 +34,7 @@ files:
|
|
39
34
|
- lib/barista.rb
|
40
35
|
- lib/barista/compiler.rb
|
41
36
|
- lib/barista/filter.rb
|
37
|
+
- lib/barista/framework.rb
|
42
38
|
- lib/barista/tasks/barista.rake
|
43
39
|
- lib/barista/version.rb
|
44
40
|
- lib/generators/barista_install/USAGE
|
@@ -57,20 +53,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
53
|
requirements:
|
58
54
|
- - ">="
|
59
55
|
- !ruby/object:Gem::Version
|
60
|
-
segments:
|
61
|
-
- 0
|
62
56
|
version: "0"
|
57
|
+
version:
|
63
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
59
|
requirements:
|
65
60
|
- - ">="
|
66
61
|
- !ruby/object:Gem::Version
|
67
|
-
segments:
|
68
|
-
- 0
|
69
62
|
version: "0"
|
63
|
+
version:
|
70
64
|
requirements: []
|
71
65
|
|
72
66
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.5
|
74
68
|
signing_key:
|
75
69
|
specification_version: 3
|
76
70
|
summary: Transparent coffeescript support for rails 3
|