noumenon 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # 0.1.2
2
+
3
+ ## New Features
4
+
5
+ * Started keeping a changelog.
6
+ * Added the `assign_to` and `item_at_path` filters for use in templates.
7
+
8
+ ## Bug Fixes
9
+
10
+ * Attempting to use a theme which is not loaded will no longer result in an infinite loop.
data/README.md CHANGED
@@ -69,6 +69,9 @@ If not specified the type defaults to "string", the label to a capitalised versi
69
69
 
70
70
  Any fields provided to a template which aren't specified will still be available in the Liquid template part.
71
71
 
72
+ Templates are written using Liquid, and so all the [standard tags and filters](https://github.com/tobi/liquid/wiki/Liquid-for-Designers)
73
+ are available, as well as the ones documented at [Noumenon::Template::CoreTags](http://rubydoc.info/gems/noumenon/Noumenon/Template/CoreTags).
74
+
72
75
  #### Layouts
73
76
 
74
77
  Layouts are used to wrap a piece of content with the overall look and feel of your website, and are provided with a single field
@@ -0,0 +1,17 @@
1
+ Feature: Including content in a template
2
+ As a designer
3
+ I want to include a piece of content within a page
4
+ So that it can be changed by the end user
5
+
6
+ Scenario: The content item exists
7
+ Given this template exists at "inclusion.nou.html"
8
+ """
9
+ {{ "/includes/header" | item_at_path | assign_to: "header" }}
10
+ <h1>{{ header.title }}</h1>
11
+ """
12
+ And this content item exists at "/inclusion"
13
+ | template | inclusion |
14
+ And this content item exists at "/includes/header"
15
+ | title | The site title |
16
+ When I view "/inclusion"
17
+ Then the headline should be "The site title"
@@ -0,0 +1,3 @@
1
+ When /^I have loaded the example tags$/ do
2
+ require 'noumenon/spec/example_tags'
3
+ end
@@ -0,0 +1,32 @@
1
+ Feature: Registering template extensions
2
+ As a developer
3
+ I want to register Liquid extensions
4
+ So that my designers can use the application I'm writing
5
+
6
+ Scenario: Registering a tag
7
+ Given this template exists at "tag.nou.html"
8
+ """
9
+ {% hello_world %}
10
+ """
11
+ And this content item exists at "/tag"
12
+ | template | tag |
13
+ And I have loaded the example tags
14
+ When I view "/tag"
15
+ Then the page content should be:
16
+ """
17
+ Hello, world!
18
+ """
19
+
20
+ Scenario: Registering a filter
21
+ Given this template exists at "filter.nou.html"
22
+ """
23
+ {{ "hello" | opposite_day }}
24
+ """
25
+ And this content item exists at "/filter"
26
+ | template | filter |
27
+ And I have loaded the example tags
28
+ When I view "/filter"
29
+ Then the page content should be:
30
+ """
31
+ goodbye
32
+ """
@@ -0,0 +1,18 @@
1
+ require 'noumenon/template'
2
+
3
+ module Noumenon::Spec::ExampleTags
4
+ class HelloWorldTag < Liquid::Tag
5
+ def render(context)
6
+ "Hello, world!"
7
+ end
8
+ end
9
+ Liquid::Template.register_tag 'hello_world', HelloWorldTag
10
+
11
+ module OppositeDayFilter
12
+ def opposite_day(input)
13
+ return "goodbye" if input == "hello"
14
+ input
15
+ end
16
+ end
17
+ Liquid::Template.register_filter(OppositeDayFilter)
18
+ end
@@ -0,0 +1,42 @@
1
+ require 'noumenon/template'
2
+
3
+ # Liquid extensions provided by Noumenon.
4
+ #
5
+ # @see [ Noumenon::Template::CoreTags::Filters ]
6
+ module Noumenon::Template::CoreTags
7
+ # The core set of filters provided by Noumenon for use in templates.
8
+ #
9
+ # @api public
10
+ module Filters
11
+ # Assigns the data piped in to the named variable.
12
+ #
13
+ # @example
14
+ # {{ "Jon" | assign_to: "name" }}
15
+ # {{ name }}
16
+ #
17
+ # @api public
18
+ def assign_to(input, variable)
19
+ @context.scopes.last[variable] = input
20
+ ''
21
+ end
22
+
23
+ # Loads the content item at the path provided and passes it on.
24
+ #
25
+ # If nothing was found then nothing will be returned, allowing the presence
26
+ # of some content to be checked before trying to use it.
27
+ #
28
+ # @example
29
+ # {{ "/includes/site_details" | item_at_path | assign_to: "site" }}
30
+ # {% if site %}
31
+ # <h1>{{ site.title }}</h1>
32
+ # <p>Written by {{ site.author }}</p>
33
+ # {% end %}
34
+ #
35
+ # @api public
36
+ def item_at_path(input)
37
+ item = Noumenon.content_repository.get(input)
38
+ item ? item.stringify_keys : nil
39
+ end
40
+ end
41
+ Liquid::Template.register_filter(Filters)
42
+ end
@@ -1,5 +1,5 @@
1
- require 'noumenon'
2
1
  require 'liquid'
2
+ require 'noumenon'
3
3
 
4
4
  # Templates specify the structure and presentation of a particular piece of content in
5
5
  # a Noumenon site, and are usually provided by a theme.
@@ -86,6 +86,14 @@ class Noumenon::Template
86
86
  self.new(path, content, fields)
87
87
  end
88
88
 
89
+ def self.drops
90
+ @drops ||= {}
91
+ end
92
+
93
+ def self.register_drop(name, klass)
94
+ drops[name] = klass
95
+ end
96
+
89
97
  # Creates a new Template instance.
90
98
  #
91
99
  # @api public
@@ -123,7 +131,9 @@ class Noumenon::Template
123
131
  end
124
132
 
125
133
  raise MissingContentError.new("The following fields were missing from your content: #{missing_fields.sort.join(", ")}") unless missing_fields.empty?
126
-
127
- Liquid::Template.parse(content).render(fields_from_page)
134
+
135
+ Liquid::Template.parse(content).render(fields_from_page.merge(self.class.drops))
128
136
  end
129
137
  end
138
+
139
+ require 'noumenon/template/core_tags'
@@ -1,5 +1,5 @@
1
1
  module Noumenon
2
2
  # The current version of Noumenon.
3
3
  # @api public
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/noumenon.rb CHANGED
@@ -69,6 +69,7 @@ module Noumenon
69
69
  if theme.is_a? Noumenon::Theme
70
70
  @theme = theme
71
71
  else
72
+ raise ArgumentError.new("The theme '#{theme}' has not been loaded.") unless Noumenon::Theme.themes.key?(theme)
72
73
  self.theme = Noumenon::Theme.themes[theme]
73
74
  end
74
75
 
@@ -24,7 +24,7 @@ describe Noumenon do
24
24
 
25
25
  context "when assigning a theme name" do
26
26
  around do |example|
27
- with_temporary_theme do
27
+ with_temporary_theme(name: "Example Theme") do
28
28
  example.run
29
29
  end
30
30
  end
@@ -37,7 +37,16 @@ describe Noumenon do
37
37
  end
38
38
 
39
39
  it "raises an ArgumentError if it has not been registered" do
40
+ error_raised = false
40
41
 
42
+ begin
43
+ Noumenon.theme = "Unloaded Theme"
44
+ rescue ArgumentError => e
45
+ error_raised = true
46
+ e.to_s.should == "The theme 'Unloaded Theme' has not been loaded."
47
+ end
48
+
49
+ error_raised.should be_true
41
50
  end
42
51
  end
43
52
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: noumenon
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jon Wood
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-25 00:00:00 +01:00
13
+ date: 2011-05-26 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -159,6 +159,7 @@ files:
159
159
  - .gitignore
160
160
  - .travis.yml
161
161
  - .yardopts
162
+ - CHANGELOG.md
162
163
  - Gemfile
163
164
  - MIT-LICENSE
164
165
  - README.md
@@ -166,15 +167,18 @@ files:
166
167
  - bin/noumenon
167
168
  - features/dynamic_template_rendering.feature
168
169
  - features/generator/site_generator.feature
170
+ - features/including_content_from_a_template.feature
169
171
  - features/mounted_applications.feature
170
172
  - features/static_template_rendering.feature
171
173
  - features/step_definitions/asset_steps.rb
172
174
  - features/step_definitions/content_steps.rb
173
175
  - features/step_definitions/generator_steps.rb
176
+ - features/step_definitions/liquid_steps.rb
174
177
  - features/step_definitions/request_steps.rb
175
178
  - features/step_definitions/theme_steps.rb
176
179
  - features/support/env.rb
177
180
  - features/support/theme/theme.yml
181
+ - features/template_extensions.feature
178
182
  - features/theme_assets.feature
179
183
  - generators/repository/index.yml
180
184
  - generators/site/Gemfile
@@ -190,9 +194,11 @@ files:
190
194
  - lib/noumenon/repository/file_system.rb
191
195
  - lib/noumenon/spec.rb
192
196
  - lib/noumenon/spec/example_app.rb
197
+ - lib/noumenon/spec/example_tags.rb
193
198
  - lib/noumenon/spec/theme_helpers.rb
194
199
  - lib/noumenon/string_extensions.rb
195
200
  - lib/noumenon/template.rb
201
+ - lib/noumenon/template/core_tags.rb
196
202
  - lib/noumenon/theme.rb
197
203
  - lib/noumenon/theme/assets_middleware.rb
198
204
  - lib/noumenon/version.rb
@@ -237,15 +243,18 @@ summary: A flexible content management system.
237
243
  test_files:
238
244
  - features/dynamic_template_rendering.feature
239
245
  - features/generator/site_generator.feature
246
+ - features/including_content_from_a_template.feature
240
247
  - features/mounted_applications.feature
241
248
  - features/static_template_rendering.feature
242
249
  - features/step_definitions/asset_steps.rb
243
250
  - features/step_definitions/content_steps.rb
244
251
  - features/step_definitions/generator_steps.rb
252
+ - features/step_definitions/liquid_steps.rb
245
253
  - features/step_definitions/request_steps.rb
246
254
  - features/step_definitions/theme_steps.rb
247
255
  - features/support/env.rb
248
256
  - features/support/theme/theme.yml
257
+ - features/template_extensions.feature
249
258
  - features/theme_assets.feature
250
259
  - spec/noumenon/repository/file_system_spec.rb
251
260
  - spec/noumenon/repository_spec.rb