cutaneous 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 702a4ccd825a31c0136fba20ad088b14e6594252
4
+ data.tar.gz: a1719c431d6f5b5c4c18575acab709d70082878e
5
+ SHA512:
6
+ metadata.gz: 13a594778df91b6a0dc7524f7611982a198243646dc507317e227fb3f5ad7edd4530eb4496e8e2850a54eefe3b351a5da23b4abd1a2974993048e4492af73cf6
7
+ data.tar.gz: 7d792d27a5416f83787e4e860cfcb9d4ea3972c2b8afe578aee69df68a8557e508a572b0e4b9a5af3201afb0b2531db902e1823c12a81933da518a2fc3963b8a
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Cutaneous
2
2
 
3
+ **Cutaneous** _adj._ Of the skin.
4
+
3
5
  Cutaneous is a Ruby (1.9+) templating engine designed for flexibility and simplicity.
4
6
 
5
7
  It supports having multiple output formats, multiple syntaxes and borrows a template inheritance mechanism from Python template engines such as [Django's](https://docs.djangoproject.com/en/dev/topics/templates/), [Jinja](http://jinja.pocoo.org/) and [Mako](http://www.makotemplates.org/).
@@ -12,6 +14,91 @@ Cutaneous is the template engine designed for and used by [Spontaneous CMS](http
12
14
 
13
15
  <script src="https://gist.github.com/3169327.js"> </script>
14
16
 
17
+ The `Cutaneous::Engine` class provides two core methods:
18
+
19
+ - `Cutaneous::Engine#render(template_path, context, format)`
20
+
21
+ This renders the template at `template_path` using the context `context` (which must be an instance of Cutaneous::Context (or a subclass)) and the format `format`.
22
+
23
+ `template_path` should be specified as either a relative path which will be resolved using a search through the template roots specified in the engine's initialisation call. See below for more information about how templates are specified & resolved.
24
+
25
+ - `Cutaneous::Engine#render_string(template, context, format)`
26
+
27
+ This takes the input string as the template and renders it. If this string references other templates through includes (see below) these are resolved as if you had made a call to `Engine#render`.
28
+
29
+ ### Template Naming & Resolution
30
+
31
+ By default Cutaneous templates should be given a `.cut` file extension.
32
+
33
+ Cutaneous generally relies upon relative template names. If we consider the following code:
34
+
35
+ ```ruby
36
+
37
+ engine = Cutaneous::Engine.new([
38
+ "/home/user/templates",
39
+ "/home/user/shared_templates"
40
+ ])
41
+
42
+ context = Cutaneous::Context.new(Object.new, title: "Welcome")
43
+
44
+ result = engine.render("welcome", context, "html")
45
+ ```
46
+
47
+ The `#render` call will look for a file called `welcome.html.cut` under each of the supplied template roots & return the first one it finds:
48
+
49
+ ```ruby
50
+
51
+ # The template resolution is equivalent to the following Ruby code:
52
+ search_paths = [
53
+ "/home/user/templates/welcome.html.cut",
54
+ "/home/user/shared_templates/welcome.html.cut"
55
+ ]
56
+
57
+ template_path = search_paths.detect { |path| File.exist?(path) }
58
+
59
+ ```
60
+
61
+ Template filenames are derived from `[template_relative_path, format, "cut"].join(".")`.
62
+
63
+ If you specified a different format for the render call, e.g. `engine.render("welcome", context, "txt")` then the engine would instead look for a file named `welcome.txt.cut`.
64
+
65
+ If you want to organise your templates into subdirectories then you are completely free to do so, you just need to add the subdirectory name onto the relative path:
66
+
67
+ ```ruby
68
+
69
+ result = engine.render("layouts/welcome", context, "html")
70
+
71
+ #=> Renders the file "/home/user/templates/layouts/welcome.html.cut"
72
+ ```
73
+
74
+ #### Includes
75
+
76
+ To include one template file into another you use the `include` directive within your template:
77
+
78
+ %{ include 'partial/header' }
79
+
80
+ This will include the output of rendering the file "/home/user/templates/partial/header.html.cut" directly in your original template's output (assuming you're rendering the "html" format).
81
+
82
+ Note that Cutaneous has no special treatment of "partials", there is no special `partial` command and no preceeding underscore in the template name.
83
+
84
+ #### Passing a Proc as a Template
85
+
86
+ If you want to switch between rendering file based & string based templates then Cutaneous provides a way of using the same `Engine#render` call by passing a Proc as the template path:
87
+
88
+ ```ruby
89
+
90
+ # This
91
+ template = "Hello ${ name }!"
92
+ engine.render(Proc.new { template }, context)
93
+
94
+ # is the same as:
95
+ engine.render_string(template, context)
96
+
97
+ ```
98
+
99
+ This allows us to use simple strings as template paths and still use a consistent calling mechanism.
100
+
101
+
15
102
  ## Features
16
103
 
17
104
  ### Template Inheritance
@@ -49,6 +136,8 @@ So for example using the following templates:
49
136
 
50
137
  The template hierarchy can be as long as you need/like. Template 'd' could extend 'c' which extends 'b' which extends 'a' etc..
51
138
 
139
+
140
+
52
141
  ### Formats
53
142
 
54
143
  Cutaneous allows templates for multiple formats to exist alongside each other. In the examples above the `html` format is exclsuively used but instead of this I could render the same template as `txt`
@@ -111,20 +200,20 @@ If you want to add features to your context, or `helpers` as they would be known
111
200
 
112
201
  ```ruby
113
202
 
114
- module MyHelperMethods
115
- def my_helpful_method
116
- # ... do something complex that you want to keep out of the template
117
- end
118
- end
203
+ module MyHelperMethods
204
+ def my_helpful_method
205
+ # ... do something complex that you want to keep out of the template
206
+ end
207
+ end
119
208
 
120
- # You *must* inherit from Cutaneous::Context!
121
- class MyContext < Cutaneous::Context
122
- include MyHelperMethods
123
- end
209
+ # You *must* inherit from Cutaneous::Context!
210
+ class MyContext < Cutaneous::Context
211
+ include MyHelperMethods
212
+ end
124
213
 
125
- context = MyContext.new(instance, parameter: "value")
214
+ context = MyContext.new(instance, parameter: "value")
126
215
 
127
- result = engine.render("template", context)
216
+ result = engine.render("template", context)
128
217
  ```
129
218
 
130
219
  ### Errors
@@ -132,11 +221,11 @@ If you want to add features to your context, or `helpers` as they would be known
132
221
  Cutaneous silently swallows errors about missing expressions in templates. If you want to instead report these errors override the `__handle_error` context method:
133
222
 
134
223
  ```ruby
135
- class MyContext < Cutaneous::Context
136
- def __handle_error(e)
137
- logger.warn(e)
138
- end
139
- end
224
+ class MyContext < Cutaneous::Context
225
+ def __handle_error(e)
226
+ logger.warn(e)
227
+ end
228
+ end
140
229
  ```
141
230
 
142
231
  Cutaneous will do its best to keep the line numbers consistent between templates and the generated code (although see "Bugs" below...). This will hopefully make debugging easier.
data/cutaneous.gemspec CHANGED
@@ -14,15 +14,15 @@ Gem::Specification.new do |s|
14
14
  ## If your rubyforge_project name is different, then edit it and comment out
15
15
  ## the sub! line in the Rakefile
16
16
  s.name = 'cutaneous'
17
- s.version = '0.1.3'
18
- s.date = '2012-07-25'
17
+ s.version = '0.1.4'
18
+ s.date = '2013-08-17'
19
19
  s.rubyforge_project = 'cutaneous'
20
20
 
21
21
  ## Make sure your summary is short. The description may be as long
22
22
  ## as you like.
23
23
  s.summary = "A Ruby templating language with Django style template inheritance"
24
24
  s.description = "Cutaneous is the Ruby templating language designed for " \
25
- "use with Spontaneous CMS. It has a simple syntax but powerful" \
25
+ "use with Spontaneous CMS. It has a simple syntax but powerful " \
26
26
  "features such as Djano style template inheritance through blocks."
27
27
 
28
28
  ## List the primary authors. If there are a bunch of authors, it's probably
data/lib/cutaneous.rb CHANGED
@@ -7,7 +7,7 @@ require 'cutaneous/lexer'
7
7
  require 'cutaneous/compiler'
8
8
 
9
9
  module Cutaneous
10
- VERSION = "0.1.3"
10
+ VERSION = "0.1.4"
11
11
 
12
12
  class CompilationError < Exception; end
13
13
 
@@ -30,8 +30,8 @@ module Cutaneous
30
30
 
31
31
  SecondPassSyntax = Cutaneous::Syntax.new({
32
32
  :comment => %w(!{ }),
33
- :expression => %w({{ }}),
34
- :escaped_expression => %w({$ $}),
33
+ :expression => %w({{{ }}}),
34
+ :escaped_expression => %w({{ }}),
35
35
  :statement => %w({% %})
36
36
  })
37
37
  end
@@ -1 +1 @@
1
- This is {{ right }} {$ code $}
1
+ This is {{ right }} {{ code }} {{{ code }}}
data/test/test_core.rb CHANGED
@@ -37,7 +37,7 @@ describe "Second pass parser" do
37
37
  it "will parse & execute a simple template with expressions" do
38
38
  context = ContextHash(right: "right", code: "<tag/>")
39
39
  result = subject.render("expressions2", context)
40
- result.must_equal "This is right &lt;tag/&gt;\n"
40
+ result.must_equal "This is right &lt;tag/&gt; <tag/>\n"
41
41
  end
42
42
 
43
43
  it "will parse & execute a simple template with statements" do
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cutaneous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Garry Hill
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-25 00:00:00.000000000 Z
11
+ date: 2013-08-17 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Cutaneous is the Ruby templating language designed for use with Spontaneous
15
- CMS. It has a simple syntax but powerfulfeatures such as Djano style template inheritance
14
+ CMS. It has a simple syntax but powerful features such as Djano style template inheritance
16
15
  through blocks.
17
16
  email: garry@magnetised.net
18
17
  executables: []
@@ -69,26 +68,25 @@ files:
69
68
  - test/test_core.rb
70
69
  homepage: https://github.com/SpontaneousCMS/cutaneous
71
70
  licenses: []
71
+ metadata: {}
72
72
  post_install_message:
73
73
  rdoc_options:
74
74
  - --charset=UTF-8
75
75
  require_paths:
76
76
  - lib
77
77
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
78
  requirements:
80
- - - ! '>='
79
+ - - '>='
81
80
  - !ruby/object:Gem::Version
82
81
  version: 1.9.2
83
82
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
83
  requirements:
86
- - - ! '>='
84
+ - - '>='
87
85
  - !ruby/object:Gem::Version
88
86
  version: '0'
89
87
  requirements: []
90
88
  rubyforge_project: cutaneous
91
- rubygems_version: 1.8.21
89
+ rubygems_version: 2.0.3
92
90
  signing_key:
93
91
  specification_version: 2
94
92
  summary: A Ruby templating language with Django style template inheritance