curly-templates 0.1.0 → 0.1.1
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/README.md +11 -0
- data/Rakefile +0 -5
- data/curly-templates.gemspec +3 -2
- data/lib/curly-templates.rb +1 -0
- data/lib/curly.rb +28 -24
- metadata +4 -3
data/README.md
CHANGED
@@ -22,6 +22,17 @@ or [Handlebars](http://handlebarsjs.com/), Curly is different in some key ways:
|
|
22
22
|
object methods that are in turn used by the template.
|
23
23
|
|
24
24
|
|
25
|
+
Installing
|
26
|
+
----------
|
27
|
+
|
28
|
+
Installing Curly is as simple as running `gem install curly-templates`. If you're
|
29
|
+
using Bundler to manage your dependencies, add this to your Gemfile
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'curly-templates', '~> 0.1.0', require: 'curly'
|
33
|
+
```
|
34
|
+
|
35
|
+
|
25
36
|
Examples
|
26
37
|
--------
|
27
38
|
|
data/Rakefile
CHANGED
@@ -120,11 +120,6 @@ end
|
|
120
120
|
|
121
121
|
desc "Validate #{gemspec_file}"
|
122
122
|
task :validate do
|
123
|
-
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
124
|
-
unless libfiles.empty?
|
125
|
-
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
126
|
-
exit!
|
127
|
-
end
|
128
123
|
unless Dir['VERSION*'].empty?
|
129
124
|
puts "A `VERSION` file at root level violates Gem best practices."
|
130
125
|
exit!
|
data/curly-templates.gemspec
CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.rubygems_version = '1.3.5'
|
5
5
|
|
6
6
|
s.name = 'curly-templates'
|
7
|
-
s.version = '0.1.
|
8
|
-
s.date = '2013-01-
|
7
|
+
s.version = '0.1.1'
|
8
|
+
s.date = '2013-01-23'
|
9
9
|
|
10
10
|
s.summary = "Free your views!"
|
11
11
|
s.description = "A view layer for your Rails apps that separates structure and logic."
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
README.md
|
30
30
|
Rakefile
|
31
31
|
curly-templates.gemspec
|
32
|
+
lib/curly-templates.rb
|
32
33
|
lib/curly.rb
|
33
34
|
lib/curly/presenter.rb
|
34
35
|
lib/curly/railtie.rb
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'curly'
|
data/lib/curly.rb
CHANGED
@@ -26,41 +26,45 @@
|
|
26
26
|
# See Curly::Presenter for more information on presenters.
|
27
27
|
#
|
28
28
|
module Curly
|
29
|
-
VERSION = "0.1.
|
29
|
+
VERSION = "0.1.1"
|
30
30
|
|
31
31
|
REFERENCE_REGEX = %r(\{\{(\w+)\}\})
|
32
32
|
|
33
33
|
class InvalidReference < StandardError
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
source = template.inspect
|
38
|
-
source.gsub!(REFERENCE_REGEX) { compile_reference($1) }
|
36
|
+
class << self
|
39
37
|
|
40
|
-
|
41
|
-
|
38
|
+
def compile(template)
|
39
|
+
source = template.inspect
|
40
|
+
source.gsub!(REFERENCE_REGEX) { compile_reference($1) }
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
methods = presenter_class.available_methods.map(&:to_s)
|
46
|
-
references & methods == references
|
47
|
-
end
|
42
|
+
source
|
43
|
+
end
|
48
44
|
|
49
|
-
|
45
|
+
def valid?(template, presenter_class)
|
46
|
+
references = extract_references(template)
|
47
|
+
methods = presenter_class.available_methods.map(&:to_s)
|
48
|
+
references & methods == references
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
private
|
52
|
+
|
53
|
+
def compile_reference(reference)
|
54
|
+
%(\#{
|
55
|
+
if presenter.method_available?(:#{reference})
|
56
|
+
result = presenter.#{reference} {|*args| yield(*args) }
|
57
|
+
ERB::Util.html_escape(result)
|
58
|
+
else
|
59
|
+
raise Curly::InvalidReference, "invalid reference `{{#{reference}}}'"
|
60
|
+
end
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
def extract_references(template)
|
65
|
+
template.scan(REFERENCE_REGEX).flatten
|
66
|
+
end
|
61
67
|
|
62
|
-
def self.extract_references(template)
|
63
|
-
template.scan(REFERENCE_REGEX).flatten
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curly-templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
71
|
- curly-templates.gemspec
|
72
|
+
- lib/curly-templates.rb
|
72
73
|
- lib/curly.rb
|
73
74
|
- lib/curly/presenter.rb
|
74
75
|
- lib/curly/railtie.rb
|
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
segments:
|
94
95
|
- 0
|
95
|
-
hash:
|
96
|
+
hash: -3306742458990639659
|
96
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
98
|
none: false
|
98
99
|
requirements:
|