subakva-bourbon 0.1.1

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/CHANGES ADDED
@@ -0,0 +1,5 @@
1
+ = 0.1.0
2
+ * Initial release
3
+
4
+ = 0.1.1
5
+ * Removed unnecessary layout hack
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 Jason Wadsworth
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = Bourbon
2
+
3
+ Bourbon is an extension to the Sinatra web application framework which
4
+ integrates the Liquid template engine into the standard Sinatra template
5
+ rendering system.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rake/clean'
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+
5
+ task :default => [:test]
6
+
7
+ desc 'Run all tests'
8
+ task :test do
9
+ Rake::Task['classic_test'].invoke
10
+ Rake::Task['modular_test'].invoke
11
+ end
12
+
13
+ desc 'Run the tests in classic app mode'
14
+ task :classic_test do
15
+ puts ''
16
+ puts '### Running classic-mode test...'
17
+ puts ''
18
+
19
+ ENV['RACK_ENV'] = 'classic'
20
+ Rake::Task['run_tests'].reenable
21
+ Rake::Task['run_tests'].invoke
22
+ end
23
+
24
+ desc 'Run the tests in modular app mode'
25
+ task :modular_test do
26
+ puts ''
27
+ puts '### Running modular-mode test...'
28
+ puts ''
29
+
30
+ ENV['RACK_ENV'] = 'modular'
31
+ Rake::Task['run_tests'].reenable
32
+ Rake::Task['run_tests'].invoke
33
+ end
34
+
35
+ Rake::TestTask.new(:run_tests) do |t|
36
+ t.test_files = FileList['test/**/*_test.rb']
37
+ t.ruby_opts = ['-rubygems'] if defined? Gem
38
+ end
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ 1. Test Without Duplication
2
+ A. Figure out why the classic test implementation doesn't auto-load the
3
+ taster module and remove the duplicate routes, templates, and filters.
data/bourbon.gemspec ADDED
@@ -0,0 +1,47 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+
5
+ s.name = 'bourbon'
6
+ s.version = '0.1.1'
7
+ s.date = '2009-05-08'
8
+
9
+ s.description = "Liquid support for Sinatra"
10
+ s.summary = "Liquid support for Sinatra"
11
+
12
+ s.authors = ["Jason Wadsworth"]
13
+ s.email = "jdwadsworth@gmail.com"
14
+
15
+ # = MANIFEST =
16
+ s.files = %w[
17
+ CHANGES
18
+ LICENSE
19
+ README.rdoc
20
+ TODO
21
+ Rakefile
22
+ lib/sinatra/bourbon.rb
23
+ bourbon.gemspec
24
+ test/app/classic.rb
25
+ test/app/modular.rb
26
+ test/app/taster.rb
27
+ test/app/views/file.erb
28
+ test/app/views/file.liquid
29
+ test/app/views/layout.erb
30
+ test/app/views/layout.liquid
31
+ test/helper.rb
32
+ test/sinatra/bourbon_test.rb
33
+ ]
34
+ # = MANIFEST =
35
+
36
+ s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
37
+
38
+ s.extra_rdoc_files = %w[README.rdoc LICENSE]
39
+ s.add_dependency 'sinatra', '>= 0.9.1'
40
+
41
+ s.has_rdoc = true
42
+ s.homepage = "http://github.com/subakva/bourbon/tree"
43
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bourbon", "--main", "README.rdoc"]
44
+ s.require_paths = %w[lib]
45
+ s.rubyforge_project = 'bourbon'
46
+ s.rubygems_version = '1.3.1'
47
+ end
@@ -0,0 +1,41 @@
1
+ require 'sinatra/base'
2
+
3
+ module Sinatra
4
+ module Bourbon
5
+
6
+ def liquid(template = nil, options = {}, &block)
7
+ require 'liquid' unless defined? ::Liquid
8
+ template = block if template.nil?
9
+ options.merge!(:layout => false) # Liquid does not support layouts.
10
+ self.send(:render, :liquid, template, options)
11
+ end
12
+
13
+ def render_liquid(template, data, options, &block)
14
+ context = {}
15
+
16
+ # Exclude variables that are created by Sintra, these can be explicitly
17
+ # included in the locals.
18
+ # - One exception is @params, which ought to be accessible in the
19
+ # template.
20
+ # - Revisit this if it turns out to be stupid.
21
+ known_sinatra_vars = [
22
+ '@response','@status','@body','@env', '@app', '@block_params',
23
+ '@request'
24
+ ]
25
+ var_names = self.instance_variables - known_sinatra_vars
26
+ var_names.each do |var_name|
27
+ var_value = self.instance_variable_get(var_name)
28
+ context[var_name.gsub(/^@/,'')] = var_value
29
+ end
30
+
31
+ # merge explicit locals into the Liquid context
32
+ locals = options[:locals] || {}
33
+ context.merge!(locals)
34
+
35
+ t = ::Liquid::Template.parse(data)
36
+ t.render(context)
37
+ end
38
+ end
39
+ helpers Bourbon
40
+ end
41
+
@@ -0,0 +1,39 @@
1
+ require 'sinatra'
2
+ require 'sinatra/bourbon'
3
+
4
+ # I'm missing something here. It should be loading the routes and helpers, but all I see are 404s..
5
+ # require File.join(File.dirname(__FILE__), 'taster')
6
+
7
+ before do
8
+ @name = 'Frank'
9
+ end
10
+
11
+ get '/liquid/file' do
12
+ liquid :file
13
+ end
14
+
15
+ get '/liquid/inline' do
16
+ liquid :inline_liquid
17
+ end
18
+
19
+ get '/liquid/block' do
20
+ liquid do
21
+ "This is a block template, {{name}}."
22
+ end
23
+ end
24
+
25
+ get '/erb/file' do
26
+ erb :file
27
+ end
28
+
29
+ get '/erb/inline' do
30
+ erb :inline_erb
31
+ end
32
+
33
+ __END__
34
+
35
+ @@ inline_liquid
36
+ This is an inline Liquid template, {{name}}.
37
+
38
+ @@ inline_erb
39
+ This is an inline ERB template, <%= @name %>.
@@ -0,0 +1,8 @@
1
+ require 'sinatra/base'
2
+ require File.join(File.dirname(__FILE__), 'taster')
3
+
4
+ module Bourbon
5
+ class Tester < Sinatra::Base
6
+ register Sinatra::BourbonTaster
7
+ end
8
+ end
@@ -0,0 +1,46 @@
1
+ require 'sinatra/bourbon'
2
+
3
+ module Sinatra
4
+ module BourbonTaster
5
+ def self.registered(app)
6
+ app.helpers Sinatra::Bourbon
7
+
8
+ app.before do
9
+ @name = 'Frank'
10
+ end
11
+
12
+ app.get '/liquid/file' do
13
+ liquid :file
14
+ end
15
+
16
+ app.get '/liquid/inline' do
17
+ liquid :inline_liquid
18
+ end
19
+
20
+ app.get '/liquid/block' do
21
+ liquid do
22
+ "This is a block template, {{name}}."
23
+ end
24
+ end
25
+
26
+ app.get '/erb/file' do
27
+ erb :file
28
+ end
29
+
30
+ app.get '/erb/inline' do
31
+ erb :inline_erb
32
+ end
33
+
34
+ app.use_in_file_templates!
35
+ end
36
+ end
37
+ register BourbonTaster
38
+ end
39
+
40
+ __END__
41
+
42
+ @@ inline_liquid
43
+ This is an inline Liquid template, {{name}}.
44
+
45
+ @@ inline_erb
46
+ This is an inline ERB template, <%= @name %>.
@@ -0,0 +1 @@
1
+ This is an ERB file template, <%= @name %>.
@@ -0,0 +1 @@
1
+ <p>This is a Liquid file template, {{name}}.</p>
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <title>ERB Layout</title>
4
+ </head>
5
+ <body>
6
+ <h1>I've got your layout right here.</h1>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>Layout Page Title</title>
4
+ </head>
5
+ <body>
6
+ <p>Liquid doesn't support templates, {{name}}. If you're seeing this in a browser, something has gone wrong.</p>
7
+ </body>
8
+ </html>
data/test/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'webrat/sinatra'
3
+ require File.join(File.dirname(__FILE__), 'app', ENV['RACK_ENV'])
4
+
5
+ Webrat.configure do |config|
6
+ config.mode = :sinatra
7
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../helper'
2
+
3
+ class BourbonTest < Test::Unit::TestCase
4
+ include Webrat::Methods
5
+ include Webrat::Matchers
6
+
7
+ if ENV['RACK_ENV'] == 'modular'
8
+ def app
9
+ Bourbon::Tester.tap do |app|
10
+ app.set :environment, :test
11
+ app.set :views, File.join(File.dirname(__FILE__), '..', 'app', 'views')
12
+ end
13
+ end
14
+ end
15
+
16
+ def assert_layout_rendered
17
+ assert_contain("I've got your layout right here.")
18
+ end
19
+
20
+ def test_liquid_file_template
21
+ visit "/liquid/file"
22
+ assert_contain("This is a Liquid file template, Frank.")
23
+ end
24
+
25
+ def test_liquid_inline_template
26
+ visit "/liquid/inline"
27
+ assert_contain("This is an inline Liquid template, Frank.")
28
+ end
29
+
30
+ def test_liquid_block_template
31
+ visit "/liquid/block"
32
+ assert_contain("This is a block template, Frank.")
33
+ end
34
+
35
+ def test_erb_file_template
36
+ visit "/erb/file"
37
+ assert_layout_rendered
38
+ assert_contain("This is an ERB file template, Frank.")
39
+ end
40
+
41
+ def test_erb_inline_template
42
+ visit "/erb/inline"
43
+ assert_layout_rendered
44
+ assert_contain("This is an inline ERB template, Frank.")
45
+ end
46
+
47
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subakva-bourbon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Wadsworth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.1
24
+ version:
25
+ description: Liquid support for Sinatra
26
+ email: jdwadsworth@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - LICENSE
34
+ files:
35
+ - CHANGES
36
+ - LICENSE
37
+ - README.rdoc
38
+ - TODO
39
+ - Rakefile
40
+ - lib/sinatra/bourbon.rb
41
+ - bourbon.gemspec
42
+ - test/app/classic.rb
43
+ - test/app/modular.rb
44
+ - test/app/taster.rb
45
+ - test/app/views/file.erb
46
+ - test/app/views/file.liquid
47
+ - test/app/views/layout.erb
48
+ - test/app/views/layout.liquid
49
+ - test/helper.rb
50
+ - test/sinatra/bourbon_test.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/subakva/bourbon/tree
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --line-numbers
56
+ - --inline-source
57
+ - --title
58
+ - Bourbon
59
+ - --main
60
+ - README.rdoc
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project: bourbon
78
+ rubygems_version: 1.2.0
79
+ signing_key:
80
+ specification_version: 2
81
+ summary: Liquid support for Sinatra
82
+ test_files:
83
+ - test/sinatra/bourbon_test.rb