puffer_pages 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Puffer pages is lightweight rails 3 CMS
1
+ # Puffer_pages is lightweight rails 3 CMS
2
2
 
3
3
  Interface of pages based on [puffer](https://github.com/puffer/puffer)
4
4
 
5
5
  ## Keyfeatures
6
6
 
7
- * Full rails integration. Puffer pages is part of rails and you can different features related to pages in rails application directly
7
+ * Full rails integration. Puffer_pages is part of rails and you can different features related to pages in rails application directly
8
8
  * Flexibility. Puffer designed to be as flexible as possible, so you can create your own functionality easily.
9
9
  * Layouts. You can use rails layouts for pages and you can use pages as action layouts!
10
10
 
@@ -16,7 +16,7 @@ Or in Gemfile:
16
16
  <pre>gem "puffer_pages"</pre>
17
17
  Next step is:
18
18
  <pre>rails g puffer_pages:install</pre>
19
- This will install puffer pages config file in your initializers, some css/js, controllers and migrations
19
+ This will install puffer_pages config file in your initializers, some css/js, controllers and migrations
20
20
  <pre>rake db:migrate</pre>
21
21
 
22
22
  To start working with admin interface, you need to have some routes like:
@@ -35,22 +35,40 @@ Just put in your routes.rb:
35
35
  <pre>puffer_page "pages/(*path)" => 'whatever#show'</pre>
36
36
  Default pages route you can see with rake routes.
37
37
 
38
- Puffer pages is radiant-like cms, so it has layouts, snippets and pages.
39
- Puffer pages use liquid as template language.
38
+ Puffer_pages is radiant-like cms, so it has layouts, snippets and pages.
39
+ Puffer_pages use liquid as template language.
40
40
 
41
41
  ## Pages.
42
42
  Pages - tree-based structure of site.
43
43
  Every page has one or more page parts.
44
+ Every page part must have main page part, named by default `body`. You can configure main page part name in config/initializers/puffer_pages.rb
44
45
 
45
46
  ## Layouts.
46
47
  Layout is page canvas, so you can draw page parts on it.
47
- In puffer pages you can use puffer pages layouts or applcation layouts.
48
+ You can use layouts from database or applcation for pages.
48
49
 
49
- ### Puffer pages layouts
50
- For puffer pages layouts page parts placeholder is liquid tag yield.
50
+ ### Application layouts.
51
+ For application layout page part body will be inserted instead of SUDDENLY! <%= yield %>
52
+ Rules are the same. If no page part name specified puffer will use page part with default name.
53
+ See `yield` liquid tag reference
54
+
55
+ So, main page part is action view and other are partials. So easy.
56
+
57
+ ## [Liquid](http://github.com/tobi/liquid/).
58
+
59
+ ### Variables.
60
+ This variables accessible from every page:
61
+ * self - current page reference.
62
+ <pre>{{ self.name }}</pre>
63
+ * root - root page reference.
64
+ <pre>{{ root.name }}</pre>
65
+ Both `self` and `root` are instances of page drop. View [this](https://github.com/puffer/puffer_pages/blob/master/lib/puffer_pages/liquid/page_drop.rb) to find list of possible page drop methods
66
+
67
+ ### yield
51
68
  <pre>{% yield [page_part_name] %}</pre>
69
+ `yield` tag is page part or actionview `content_for` placeholder.
52
70
 
53
- If no page_part_name specified, puffer layout will use page part with default name ('body'). You can change defaul page part name in puffer pages setup initializer.
71
+ If no page_part_name specified, puffer layout will use page part with default name ('body'). You can change defaul page part name in puffer_pages setup initializer.
54
72
 
55
73
  Ex.
56
74
  <pre>
@@ -60,21 +78,14 @@ Ex.
60
78
  {% yield sb %} # renders sidebar too
61
79
  </pre>
62
80
 
63
- ### Application layouts.
64
- For application layout page part body will be inserted instead of SUDDENLY! <%= yield %>
65
- Rules are the same. If no page part name specified puffer will use page part with default name.
66
-
67
- So, main page part is action view and other are partials. So easy.
68
-
69
- ## Liquid.
81
+ ### render_snippet
82
+ <pre>{% render_snippet snippet_name %}</pre>
83
+ Renders specified snippet`s content.
70
84
 
71
- The first tag was {% yield %}
72
- Also, you can acces current page and root page from puffer pages templates.
73
- Page named `self` in templates:
74
- <pre>{{ self.name }}</pre>
75
- And root page:
76
- <pre>{{ root.name }}</pre>
77
-
78
- Also you can do anything you can do with [liquid](http://github.com/tobi/liquid/)
85
+ Ex.
86
+ <pre>
87
+ {% render_snippet 'navigation' %}
88
+ {% assign nav = 'navigation' %}
89
+ {% render_snippet nav %}
90
+ </pre>
79
91
 
80
- `self` and `root` are both instances of page drop. View [this](https://github.com/puffer/puffer_pages/blob/master/lib/puffer_pages/liquid/page_drop.rb) to find list of possible page drop methods
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -4,8 +4,6 @@ class PagePart < ActiveRecord::Base
4
4
  validates_presence_of :name
5
5
  validates_uniqueness_of :name, :scope => :page_id
6
6
 
7
- attr_accessor_with_default :additional, false
8
-
9
7
  def render(drops_or_context, wrap = false)
10
8
  template = Liquid::Template.parse(body)
11
9
  result = tracker.cleanup template.render(drops_or_context, :registers => {:tracker => tracker})
@@ -1,4 +1,14 @@
1
1
  class Snippet < ActiveRecord::Base
2
2
  validates_presence_of :name
3
3
  validates_uniqueness_of :name
4
+
5
+ def render(drops_or_context)
6
+ template = Liquid::Template.parse(body)
7
+ tracker.cleanup template.render(drops_or_context, :registers => {:tracker => tracker})
8
+ end
9
+
10
+ def tracker
11
+ @tracker ||= PufferPages::Liquid::Tracker.new
12
+ end
13
+
4
14
  end
@@ -0,0 +1,33 @@
1
+ module PufferPages
2
+ module Liquid
3
+ module Tags
4
+
5
+ class RenderSnippet < ::Liquid::Tag
6
+ Syntax = /(#{::Liquid::QuotedFragment}+)/
7
+
8
+ def initialize(tag_name, markup, tokens)
9
+ if markup =~ Syntax
10
+ @name = $1
11
+ else
12
+ raise SyntaxError.new("Syntax Error in 'render_snippet' - Valid syntax: render_snippet snipper_name")
13
+ end
14
+
15
+ super
16
+ end
17
+
18
+ def render(context)
19
+ name = context[@name]
20
+ snippet = Snippet.find_by_name(name)
21
+ if snippet
22
+ snippet.render(context)
23
+ else
24
+ raise ArgumentError.new("Argument error in 'render_snippet' - Can not find snippet named '#{name}'")
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+
33
+ Liquid::Template.register_tag('render_snippet', PufferPages::Liquid::Tags::RenderSnippet)
@@ -16,7 +16,13 @@ module PufferPages
16
16
  end
17
17
 
18
18
  def render(context)
19
- context.registers[:page].part(context[@name]).render(context)
19
+ name = context[@name]
20
+ part = context.registers[:page].part(name)
21
+ if part
22
+ part.render(context)
23
+ else
24
+ raise ArgumentError.new("Argument error in 'yield' - Can not find page part named '#{name}'")
25
+ end
20
26
  end
21
27
  end
22
28
 
data/lib/puffer_pages.rb CHANGED
@@ -19,6 +19,7 @@ require 'puffer_pages/engine'
19
19
  require 'puffer_pages/extensions/core'
20
20
  require 'puffer_pages/extensions/mapper'
21
21
  require 'puffer_pages/liquid/tags/yield'
22
+ require 'puffer_pages/liquid/tags/render_snippet'
22
23
 
23
24
  Puffer.setup do |config|
24
25
  config.javascripts += %w(right-dialog right-tabs puffer_pages)
data/puffer_pages.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{puffer_pages}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["pyromaniac"]
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
63
63
  "lib/puffer_pages/extensions/core.rb",
64
64
  "lib/puffer_pages/extensions/mapper.rb",
65
65
  "lib/puffer_pages/liquid/page_drop.rb",
66
+ "lib/puffer_pages/liquid/tags/render_snippet.rb",
66
67
  "lib/puffer_pages/liquid/tags/yield.rb",
67
68
  "lib/puffer_pages/liquid/tracker.rb",
68
69
  "puffer_pages.gemspec",
@@ -124,6 +125,7 @@ Gem::Specification.new do |s|
124
125
  "spec/fabricators/layouts_fabricator.rb",
125
126
  "spec/fabricators/page_parts_fabricator.rb",
126
127
  "spec/fabricators/pages_fabricator.rb",
128
+ "spec/fabricators/snippets_fabricator.rb",
127
129
  "spec/integration/navigation_spec.rb",
128
130
  "spec/models/page_spec.rb",
129
131
  "spec/models/tags_spec.rb",
@@ -164,6 +166,7 @@ Gem::Specification.new do |s|
164
166
  "spec/fabricators/layouts_fabricator.rb",
165
167
  "spec/fabricators/page_parts_fabricator.rb",
166
168
  "spec/fabricators/pages_fabricator.rb",
169
+ "spec/fabricators/snippets_fabricator.rb",
167
170
  "spec/integration/navigation_spec.rb",
168
171
  "spec/models/page_spec.rb",
169
172
  "spec/models/tags_spec.rb",
@@ -0,0 +1,4 @@
1
+ Fabricator(:snippet) do
2
+ name { Forgery::LoremIpsum.word }
3
+ body { Forgery::LoremIpsum.sentence }
4
+ end
@@ -122,9 +122,9 @@ describe Page do
122
122
  end
123
123
 
124
124
  it 'should render layout' do
125
- @layout = Fabricate :layout, :name => 'foo_layout', :body => "|{% yield %}|{% yield 'sidebar' %}|{% assign sb = 'sidebar' %}|{% yield sb %}|"
125
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% yield %} {% yield 'sidebar' %}"
126
126
  result = @root.render 'self' => PufferPages::Liquid::PageDrop.new(@root)
127
- result.should == "|#{@root.title}|#{@root.name}||#{@root.name}|"
127
+ result.should == "#{@root.title} #{@root.name}"
128
128
  end
129
129
 
130
130
  end
@@ -2,8 +2,54 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Tags' do
4
4
 
5
- #describe 'yield' do
5
+ def render_page(page)
6
+ page.render 'self' => PufferPages::Liquid::PageDrop.new(page)
7
+ end
8
+
9
+ describe 'yield' do
10
+
11
+ before :each do
12
+ @page = Fabricate :page, :layout_name => 'foo_layout'
13
+ @main = Fabricate :page_part, :name => PufferPages.primary_page_part_name, :body => 'foo'
14
+ @sidebar = Fabricate :page_part, :name => 'sidebar', :body => 'bar'
15
+ @page.page_parts = [@main, @sidebar]
16
+ end
17
+
18
+ it 'should render yield without params' do
19
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% yield %}"
20
+ render_page(@page).should == @main.body
21
+ end
22
+
23
+ it 'should render yield with string param' do
24
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% yield 'sidebar' %}"
25
+ render_page(@page).should == @sidebar.body
26
+ end
27
+
28
+ it 'should render yield with variable param' do
29
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign sb = 'sidebar' %}{% yield sb %}"
30
+ render_page(@page).should == @sidebar.body
31
+ end
32
+
33
+ end
34
+
35
+ describe 'render_snippet' do
36
+
37
+ before :each do
38
+ @page = Fabricate :page, :layout_name => 'foo_layout'
39
+ @snippet = Fabricate :snippet, :name => 'snip', :body => 'snippet body'
40
+ end
41
+
42
+ it 'should render yield with string param' do
43
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% render_snippet 'snip' %}"
44
+ render_page(@page).should == @snippet.body
45
+ end
46
+
47
+ it 'should render yield with variable param' do
48
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign sn = 'snip' %}{% render_snippet sn %}"
49
+ render_page(@page).should == @snippet.body
50
+ end
51
+
52
+ end
6
53
 
7
- #end
8
54
 
9
55
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puffer_pages
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - pyromaniac
@@ -250,6 +250,7 @@ files:
250
250
  - lib/puffer_pages/extensions/core.rb
251
251
  - lib/puffer_pages/extensions/mapper.rb
252
252
  - lib/puffer_pages/liquid/page_drop.rb
253
+ - lib/puffer_pages/liquid/tags/render_snippet.rb
253
254
  - lib/puffer_pages/liquid/tags/yield.rb
254
255
  - lib/puffer_pages/liquid/tracker.rb
255
256
  - puffer_pages.gemspec
@@ -311,6 +312,7 @@ files:
311
312
  - spec/fabricators/layouts_fabricator.rb
312
313
  - spec/fabricators/page_parts_fabricator.rb
313
314
  - spec/fabricators/pages_fabricator.rb
315
+ - spec/fabricators/snippets_fabricator.rb
314
316
  - spec/integration/navigation_spec.rb
315
317
  - spec/models/page_spec.rb
316
318
  - spec/models/tags_spec.rb
@@ -380,6 +382,7 @@ test_files:
380
382
  - spec/fabricators/layouts_fabricator.rb
381
383
  - spec/fabricators/page_parts_fabricator.rb
382
384
  - spec/fabricators/pages_fabricator.rb
385
+ - spec/fabricators/snippets_fabricator.rb
383
386
  - spec/integration/navigation_spec.rb
384
387
  - spec/models/page_spec.rb
385
388
  - spec/models/tags_spec.rb