Skip to content

Commit

Permalink
Added snippet and layout tags
Browse files Browse the repository at this point in the history
  • Loading branch information
pyromaniac committed Mar 20, 2012
1 parent a0fbd00 commit 2107b16
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
19 changes: 10 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

### New features

* Added new tags `snippet` and `layout`. They acts like
a short-cuts to `include`. I.e. `{% snippet 'hello' %}`
is the same is `{% include 'snippets/hello' %}`. Both
tags supports additional parameters as `include`

* Removed `root` page object from context.

* All template assigns, not respondable to `to_liquid` are joined
to context registers, so can be used from drops.

* Ability to use render method to specify rendered page

```
Expand All @@ -25,15 +35,6 @@
If `hello/world` page body: `{{count}}`
This action will produce `42`

* Removed attributes tags. Now attributes are rendered with standart
variable call. I.e. `{{ page.title }}` - title here will be rendered
but not just inserted.

* All template assigns, not respondable to `to_liquid` are joined
to context registers, so can be used from drops.

* Removed `root` page object from context.

## 0.1.1

### New features
Expand Down
1 change: 1 addition & 0 deletions lib/puffer_pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ def self.setup

require 'puffer_pages/liquid/tags/yield'
require 'puffer_pages/liquid/tags/assets'
require 'puffer_pages/liquid/tags/include'
require 'puffer_pages/liquid/tags/attribute'
26 changes: 26 additions & 0 deletions lib/puffer_pages/liquid/tags/include.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module PufferPages
module Liquid
module Tags

class Include < ::Liquid::Include
def initialize(tag_name, markup, tokens)
@tag_name = tag_name
super
end

private

def _read_template_from_file_system(context)
file_system = context.registers[:file_system] || Liquid::Template.file_system
template_name = "#{@tag_name.pluralize}/#{context[@template_name]}"

file_system.read_template_file(template_name, context)
end
end

end
end
end

Liquid::Template.register_tag('snippet', PufferPages::Liquid::Tags::Include)
Liquid::Template.register_tag('layout', PufferPages::Liquid::Tags::Include)
5 changes: 5 additions & 0 deletions spec/lib/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def render_page(page, drops = {})
render_page(@page).should == @snippet.body
end

it 'should include snippet with string param' do
@layout = Fabricate :layout, :name => 'foo_layout', :body => "{% snippet 'snip' %}"
render_page(@page).should == @snippet.body
end

it 'should include snippet with variable param' do
@layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign sn = 'snippets/snip' %}{% include sn %}"
render_page(@page).should == @snippet.body
Expand Down

0 comments on commit 2107b16

Please sign in to comment.