sinatra-pages 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -80,9 +80,18 @@ You can try your modular application by executing the following command in your
80
80
 
81
81
  In order to verify if you application is working, open your web browser with the address that will appear after the execution described above.
82
82
 
83
- ### Customization
84
- This extension assumes the __:views__ and __:public__ configuration are located on the *./views* and *./public* directories respectively. In any case, you are able to change these values as required.
83
+ ### Built-in variables
84
+ This extension have a default configuration that assumes the __:views__ and __:public__ configuration are located on the *./views* and *./public* directories respectively. As well, it preset the __:html__ version to use as *:v5*, the way to __:format__ the HTML code as *:tidy* and the HTML __:escaping__ is disabled by default.
85
+
86
+ In any case, you are able to change these values as required.
85
87
 
88
+ * __:views__ => <*Path to your views directory*>
89
+ * __:public__ => <*Path to your public directory*>
90
+ * __:html__ => [*:v4*, *:vX*, *:v5*]
91
+ * __:format__ => [*:tidy*, *:ugly*]
92
+ * __:escaping__ => [*true*, *false*]
93
+
94
+ ### Customization
86
95
  Depending on the kind of Sinatra application you're developing, you should proceed as follows. If you follow the __Classic__ approach, then you just need to set these configuration parameters in the *app.rb* file.
87
96
 
88
97
  require 'sinatra'
data/lib/sinatra/pages.rb CHANGED
@@ -4,9 +4,16 @@ require 'haml'
4
4
  module Sinatra
5
5
  module Pages
6
6
  def self.registered(app)
7
- app.set :root, Dir.pwd
8
- app.enable :static
7
+ app.set :html, :v5
8
+ app.set :format, :tidy
9
+ app.disable :escaping
9
10
 
11
+ app.configure do
12
+ app.set :root, Dir.pwd
13
+ app.set :haml, Proc.new {setup(app)}
14
+ app.enable :static
15
+ end
16
+
10
17
  %w[/? /:page/? /*/:page/?].each do |route|
11
18
  app.get route do
12
19
  params[:page] = 'home' if params[:page].nil?
@@ -28,6 +35,22 @@ module Sinatra
28
35
  haml :not_found, :layout => !request.xhr?
29
36
  end
30
37
  end
38
+
39
+ private
40
+
41
+ def setup(app)
42
+ options = {:format => nil, :ugly => nil, :escape_html => nil}
43
+
44
+ options[:ugly] = app.format == :ugly ? true : false
45
+ options[:escape_html] = app.escaping
46
+ options[:format] = case app.html
47
+ when :v5 then :html5
48
+ when :v4 then :html4
49
+ when :vX then :xhtml
50
+ end
51
+
52
+ options
53
+ end
31
54
  end
32
55
 
33
56
  register Pages
data/spec/pages_spec.rb CHANGED
@@ -46,6 +46,45 @@ describe Sinatra::Pages do
46
46
  end
47
47
  end
48
48
 
49
+ context 'HAML settings' do
50
+ context 'by default' do
51
+ subject {app}
52
+ its(:html) {should == :v5}
53
+ its(:format) {should == :tidy}
54
+ its(:escaping) {should == false}
55
+ its(:haml) {should == {:format => :html5, :ugly => false, :escape_html => false}}
56
+ end
57
+
58
+ context 'on defining' do
59
+ before do
60
+ app.set :html, :v5
61
+ app.set :format, :tidy
62
+ app.disable :escaping
63
+ end
64
+
65
+ [:v4, :vX].each do |value|
66
+ context '#html' do
67
+ subject {app.set :html, value}
68
+ its(:html) {should == value}
69
+ it {subject.haml[:format].should == (value == :v4 ? :html4 : :xhtml)}
70
+ end
71
+ end
72
+
73
+ context '#format' do
74
+ subject {app.set :format, :ugly}
75
+ its(:format) {should == :ugly}
76
+ it {subject.haml[:ugly].should == true}
77
+ end
78
+
79
+ context '#escaping' do
80
+ #subject {app.enable :escaping}
81
+ subject {app.set :escaping, true}
82
+ its(:escaping) {should == true}
83
+ it {subject.haml[:escape_html].should == true}
84
+ end
85
+ end
86
+ end
87
+
49
88
  context 'on HTTP GET' do
50
89
  before :all do
51
90
  PAGES.each{|page| create_file_for(page, app.views)}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-pages
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 1.3.0
10
+ version: 1.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Julio Javier Cicchelli
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-03 00:00:00 +02:00
18
+ date: 2010-08-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency