eco 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +57 -0
  3. data/lib/eco.rb +51 -0
  4. metadata +110 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Sam Stephenson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ Ruby Eco
2
+ ========
3
+
4
+ Ruby Eco is a bridge to the official
5
+ [Eco](https://github.com/sstephenson/eco) compiler for embedded
6
+ CoffeeScript templates.
7
+
8
+ ```ruby
9
+ require "eco"
10
+
11
+ Eco.compile(File.read("template.eco"))
12
+ # => "function(...) {...}"
13
+
14
+ context = Eco.context_for("Hello <%= @name %>")
15
+ context.call("render", :name => "Sam")
16
+ # => "Hello Sam"
17
+
18
+ Eco.render("Hello <%= @name %>", :name => "world")
19
+ # => "Hello world"
20
+ ```
21
+
22
+ Installation
23
+ ------------
24
+
25
+ $ gem install eco
26
+
27
+
28
+ Dependencies
29
+ ------------
30
+
31
+ This library depends on the `eco-source` gem which is updated any time
32
+ a new version of Eco is released. (The `eco-source` gem's version
33
+ number is synced with each official Eco release.) This way you can
34
+ build against different versions of Eco by requiring the correct
35
+ version of the `eco-source` gem.
36
+
37
+ In addition, you can use this library with unreleased versions of Eco
38
+ by setting the `ECO_SOURCE_PATH` environment variable:
39
+
40
+ export ECO_SOURCE_PATH=/path/to/eco/dist/eco.js
41
+
42
+
43
+ ### Ruby CoffeeScript
44
+
45
+ The [Ruby CoffeeScript](https://github.com/josh/ruby-coffee-script)
46
+ library is used to load the CoffeeScript compiler source. See the
47
+ [README](https://github.com/josh/ruby-coffee-script/blob/master/README.md)
48
+ for information on loading a specific version of the CoffeeScript
49
+ compiler.
50
+
51
+ ### ExecJS
52
+
53
+ The [ExecJS](https://github.com/sstephenson/execjs) library is used to
54
+ automatically choose the best JavaScript engine for your
55
+ platform. Check out its
56
+ [README](https://github.com/sstephenson/execjs/blob/master/README.md)
57
+ for a complete list of supported engines.
@@ -0,0 +1,51 @@
1
+ require "coffee_script"
2
+ require "eco/source"
3
+ require "execjs"
4
+
5
+ module Eco
6
+ module Source
7
+ def self.path
8
+ @path ||= ENV["ECO_SOURCE_PATH"] || bundled_path
9
+ end
10
+
11
+ def self.path=(path)
12
+ @contents = @version = @context = nil
13
+ @path = path
14
+ end
15
+
16
+ def self.contents
17
+ @contents ||= File.read(path)
18
+ end
19
+
20
+ def self.combined_contents
21
+ [CoffeeScript::Source.contents, contents].join(";\n")
22
+ end
23
+
24
+ def self.version
25
+ @version ||= contents[/Eco Compiler v(.*?)\s/, 1]
26
+ end
27
+
28
+ def self.context
29
+ @context ||= ExecJS.compile(combined_contents)
30
+ end
31
+ end
32
+
33
+ class << self
34
+ def version
35
+ Source.version
36
+ end
37
+
38
+ def compile(template)
39
+ template = template.read if template.respond_to?(:read)
40
+ Source.context.call("eco.precompile", template)
41
+ end
42
+
43
+ def context_for(template)
44
+ ExecJS.compile("var render = #{compile(template)}")
45
+ end
46
+
47
+ def render(template, locals = {})
48
+ context_for(template).call("render", locals)
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eco
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Sam Stephenson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-04 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: coffee-script
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: eco-source
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: execjs
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: " Ruby Eco is a bridge to the official JavaScript Eco compiler.\n"
64
+ email: sstephenson@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - lib/eco.rb
73
+ - LICENSE
74
+ - README.md
75
+ has_rdoc: true
76
+ homepage: https://github.com/sstephenson/ruby-eco
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.5.0
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Ruby Eco Compiler (Embedded CoffeeScript templates)
109
+ test_files: []
110
+