puffer_pages 0.0.7 → 0.0.8

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 CHANGED
@@ -8,12 +8,15 @@ Interface of pages based on [puffer](https://github.com/puffer/puffer)
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
 
11
- ## Installation.
11
+ ## Installation
12
12
 
13
13
  You can instal puffer as a gem:
14
14
  <pre>gem install puffer_pages</pre>
15
15
  Or in Gemfile:
16
16
  <pre>gem "puffer_pages"</pre>
17
+
18
+ Did you install [puffer](https://github.com/puffer/puffer) properly?
19
+
17
20
  Next step is:
18
21
  <pre>rails g puffer_pages:install</pre>
19
22
  This will install puffer_pages config file in your initializers, some css/js, controllers and migrations
@@ -28,7 +31,7 @@ namespace :admin do
28
31
  end
29
32
  </pre>
30
33
 
31
- ## Introduction.
34
+ ## Introduction
32
35
 
33
36
  The first thing, you should do - setup routes if you want pages path different from /(*path).
34
37
  Just put in your routes.rb:
@@ -38,26 +41,27 @@ Default pages route you can see with rake routes.
38
41
  Puffer_pages is radiant-like cms, so it has layouts, snippets and pages.
39
42
  Puffer_pages use liquid as template language.
40
43
 
41
- ## Pages.
44
+ ## Pages
42
45
  Pages - tree-based structure of site.
43
46
  Every page has one or more page parts.
44
47
  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
45
48
 
46
- ## Layouts.
49
+ ## Layouts
47
50
  Layout is page canvas, so you can draw page parts on it.
48
51
  You can use layouts from database or applcation for pages.
49
52
 
50
- ### Application layouts.
53
+ ### Application layouts
51
54
  For application layout page part body will be inserted instead of SUDDENLY! <%= yield %>
52
55
  Rules are the same. If no page part name specified puffer will use page part with default name.
53
56
  See `yield` liquid tag reference
54
57
 
55
58
  So, main page part is action view and other are partials. So easy.
56
59
 
57
- ## [Liquid](http://github.com/tobi/liquid/).
60
+ ## [Liquid](http://github.com/tobi/liquid/)
58
61
 
59
- ### Variables.
62
+ ### Variables
60
63
  This variables accessible from every page:
64
+
61
65
  * self - current page reference.
62
66
  <pre>{{ self.name }}</pre>
63
67
  * root - root page reference.
@@ -70,7 +74,7 @@ Both `self` and `root` are instances of page drop. View [this](https://github.co
70
74
 
71
75
  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.
72
76
 
73
- Ex.
77
+ Usage example:
74
78
  <pre>
75
79
  {% yield %} # renders body
76
80
  {% yield 'sidebar' %} # renders sidebar
@@ -82,10 +86,21 @@ Ex.
82
86
  <pre>{% render_snippet snippet_name %}</pre>
83
87
  Renders specified snippet`s content.
84
88
 
85
- Ex.
89
+ Usage example:
86
90
  <pre>
87
91
  {% render_snippet 'navigation' %}
88
92
  {% assign nav = 'navigation' %}
89
93
  {% render_snippet nav %}
90
94
  </pre>
91
95
 
96
+ ### stylesheets, javascripts
97
+ <pre>{% stylesheets path [, path, path ...] %}</pre>
98
+ Both tags syntax is equal
99
+ Tags renders rail`s stylesheet_link_tag or javascript_include_tag.
100
+
101
+ Usage example:
102
+ <pre>
103
+ {% assign ctrl = 'controls' %}
104
+ {% javascripts 'prototype', ctrl %}
105
+ </pre>
106
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -31,11 +31,11 @@ module PufferPages
31
31
  end
32
32
 
33
33
  def path
34
- @page.location
34
+
35
35
  end
36
36
 
37
37
  def url
38
- @url ||= @request.protocol + @request.host_with_port + path
38
+
39
39
  end
40
40
 
41
41
  end
@@ -0,0 +1,38 @@
1
+ module PufferPages
2
+ module Liquid
3
+ module Tags
4
+
5
+ class Javascripts < ::Liquid::Tag
6
+ Syntax = /^(#{::Liquid::QuotedFragment}+)/
7
+
8
+ def initialize(tag_name, markup, tokens)
9
+ if markup =~ Syntax
10
+ @paths = variables_from_string(markup)
11
+ else
12
+ raise SyntaxError.new("Syntax Error in 'javascripts' - Valid syntax: javascripts path [, path, path ...]")
13
+ end
14
+
15
+ super
16
+ end
17
+
18
+ def render(context)
19
+ paths = @paths.map {|path| "'#{context[path]}'" }.join(', ')
20
+ context.registers[:tracker].register "<%= javascript_include_tag #{paths} %>"
21
+ end
22
+
23
+ private
24
+
25
+ def variables_from_string(markup)
26
+ markup.split(',').map do |var|
27
+ var.strip =~ /\s*(#{::Liquid::QuotedFragment})\s*/
28
+ $1 ? $1 : nil
29
+ end.compact
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+
38
+ Liquid::Template.register_tag('javascripts', PufferPages::Liquid::Tags::Javascripts)
@@ -3,7 +3,7 @@ module PufferPages
3
3
  module Tags
4
4
 
5
5
  class RenderSnippet < ::Liquid::Tag
6
- Syntax = /(#{::Liquid::QuotedFragment}+)/
6
+ Syntax = /^(#{::Liquid::QuotedFragment})/
7
7
 
8
8
  def initialize(tag_name, markup, tokens)
9
9
  if markup =~ Syntax
@@ -0,0 +1,38 @@
1
+ module PufferPages
2
+ module Liquid
3
+ module Tags
4
+
5
+ class Stylesheets < ::Liquid::Tag
6
+ Syntax = /^(#{::Liquid::QuotedFragment}+)/
7
+
8
+ def initialize(tag_name, markup, tokens)
9
+ if markup =~ Syntax
10
+ @paths = variables_from_string(markup)
11
+ else
12
+ raise SyntaxError.new("Syntax Error in 'stylesheets' - Valid syntax: stylesheets path [, path, path ...]")
13
+ end
14
+
15
+ super
16
+ end
17
+
18
+ def render(context)
19
+ paths = @paths.map {|path| "'#{context[path]}'" }.join(', ')
20
+ context.registers[:tracker].register "<%= stylesheet_link_tag #{paths} %>"
21
+ end
22
+
23
+ private
24
+
25
+ def variables_from_string(markup)
26
+ markup.split(',').map do |var|
27
+ var.strip =~ /\s*(#{::Liquid::QuotedFragment})\s*/
28
+ $1 ? $1 : nil
29
+ end.compact
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+
38
+ Liquid::Template.register_tag('stylesheets', PufferPages::Liquid::Tags::Stylesheets)
@@ -3,7 +3,7 @@ module PufferPages
3
3
  module Tags
4
4
 
5
5
  class Yield < ::Liquid::Tag
6
- Syntax = /(#{::Liquid::QuotedFragment}+)/
6
+ Syntax = /^(#{::Liquid::QuotedFragment})/
7
7
 
8
8
  def initialize(tag_name, markup, tokens)
9
9
  if markup =~ Syntax
data/lib/puffer_pages.rb CHANGED
@@ -12,6 +12,7 @@ module PufferPages
12
12
 
13
13
  end
14
14
 
15
+ require 'puffer'
15
16
  require 'liquid'
16
17
  require 'nested_set'
17
18
 
@@ -20,6 +21,8 @@ require 'puffer_pages/extensions/core'
20
21
  require 'puffer_pages/extensions/mapper'
21
22
  require 'puffer_pages/liquid/tags/yield'
22
23
  require 'puffer_pages/liquid/tags/render_snippet'
24
+ require 'puffer_pages/liquid/tags/stylesheets'
25
+ require 'puffer_pages/liquid/tags/javascripts'
23
26
 
24
27
  Puffer.setup do |config|
25
28
  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.7"
8
+ s.version = "0.0.8"
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,7 +63,9 @@ 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/javascripts.rb",
66
67
  "lib/puffer_pages/liquid/tags/render_snippet.rb",
68
+ "lib/puffer_pages/liquid/tags/stylesheets.rb",
67
69
  "lib/puffer_pages/liquid/tags/yield.rb",
68
70
  "lib/puffer_pages/liquid/tracker.rb",
69
71
  "puffer_pages.gemspec",
@@ -39,17 +39,37 @@ describe 'Tags' do
39
39
  @snippet = Fabricate :snippet, :name => 'snip', :body => 'snippet body'
40
40
  end
41
41
 
42
- it 'should render yield with string param' do
42
+ it 'should render render_snippet with string param' do
43
43
  @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% render_snippet 'snip' %}"
44
44
  render_page(@page).should == @snippet.body
45
45
  end
46
46
 
47
- it 'should render yield with variable param' do
47
+ it 'should render render_snippet with variable param' do
48
48
  @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign sn = 'snip' %}{% render_snippet sn %}"
49
49
  render_page(@page).should == @snippet.body
50
50
  end
51
51
 
52
52
  end
53
53
 
54
+ describe 'stylesheets' do
55
+
56
+ it 'should render stylesheets with proper params' do
57
+ @page = Fabricate :page, :layout_name => 'foo_layout'
58
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign st = 'styles' %}{% stylesheets 'reset', st %}"
59
+ render_page(@page).should == "<%= stylesheet_link_tag 'reset', 'styles' %>"
60
+ end
61
+
62
+ end
63
+
64
+ describe 'javascripts' do
65
+
66
+ it 'should render javascripts with proper params' do
67
+ @page = Fabricate :page, :layout_name => 'foo_layout'
68
+ @layout = Fabricate :layout, :name => 'foo_layout', :body => "{% assign ctrl = 'controls' %}{% javascripts 'prototype', ctrl %}"
69
+ render_page(@page).should == "<%= javascript_include_tag 'prototype', 'controls' %>"
70
+ end
71
+
72
+ end
73
+
54
74
 
55
75
  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: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - pyromaniac
@@ -250,7 +250,9 @@ 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/javascripts.rb
253
254
  - lib/puffer_pages/liquid/tags/render_snippet.rb
255
+ - lib/puffer_pages/liquid/tags/stylesheets.rb
254
256
  - lib/puffer_pages/liquid/tags/yield.rb
255
257
  - lib/puffer_pages/liquid/tracker.rb
256
258
  - puffer_pages.gemspec