sbfaulkner-sinatra-markaby 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +33 -0
- data/Rakefile +45 -0
- data/VERSION.yml +4 -0
- data/lib/sinatra/markaby.rb +31 -0
- data/test/sinatra_markaby_test.rb +63 -0
- data/test/test_helper.rb +17 -0
- data/test/views/hello.mab +1 -0
- metadata +71 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 unwwwired.net
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= sinatra-markaby
|
2
|
+
|
3
|
+
sinatra-markaby is an extension for sinatra to enable rendering of html files
|
4
|
+
using markaby templates.
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
sudo gem install sbfaulkner-sinatra-markaby -s http://gems.github.com
|
9
|
+
|
10
|
+
== Example
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'sinatra'
|
14
|
+
require 'sinatra/markaby'
|
15
|
+
|
16
|
+
get '/' do
|
17
|
+
markaby :template
|
18
|
+
end
|
19
|
+
|
20
|
+
__END__
|
21
|
+
|
22
|
+
@@ template
|
23
|
+
mab.html do
|
24
|
+
head { title "Hello world" }
|
25
|
+
body do
|
26
|
+
p "Hello world!!!!!"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
== Legal
|
31
|
+
|
32
|
+
Author:: S. Brent Faulkner <brentf@unwwwired.net>
|
33
|
+
License:: Copyright (c) 2009 unwwwired.net, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "sinatra-markaby"
|
7
|
+
s.summary = %Q{Sinatra plugin to enable markaby (.mab) template rendering.}
|
8
|
+
s.email = "brentf@unwwwired.net"
|
9
|
+
s.homepage = "http://github.com/sbfaulkner/sinatra-markaby"
|
10
|
+
s.description = "Sinatra plugin to enable markaby (.mab) template rendering."
|
11
|
+
s.authors = ["S. Brent Faulkner"]
|
12
|
+
s.add_dependency "markaby"
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rake/rdoctask'
|
19
|
+
Rake::RDocTask.new do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'sinatra-markaby'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README*')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << 'lib' << 'test'
|
30
|
+
t.pattern = 'test/**/*_test.rb'
|
31
|
+
t.verbose = false
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |t|
|
37
|
+
t.libs << 'test'
|
38
|
+
t.test_files = FileList['test/**/*_test.rb']
|
39
|
+
t.verbose = true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
|
45
|
+
task :default => :test
|
data/VERSION.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'markaby'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
module Markaby
|
6
|
+
# Generate html file using Markaby.
|
7
|
+
# Takes the name of a template to render as a Symbol and returns a String with the rendered output.
|
8
|
+
#
|
9
|
+
# Options for markaby may be specified in Sinatra using set :markaby, { ... }
|
10
|
+
# TODO: the options aren't actually used yet
|
11
|
+
def markaby(template=nil, options={}, locals = {}, &block)
|
12
|
+
options, template = template, nil if template.is_a?(Hash)
|
13
|
+
template = lambda { block } if template.nil?
|
14
|
+
render :mab, template, options, locals
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def render_mab(template, data, options, locals, &block)
|
19
|
+
filename = options.delete(:filename) || '<MARKABY>'
|
20
|
+
line = options.delete(:line) || 1
|
21
|
+
mab = ::Markaby::Builder.new(locals)
|
22
|
+
if data.respond_to?(:to_str)
|
23
|
+
eval(data.to_str, binding, filename, line)
|
24
|
+
elsif data.kind_of?(Proc)
|
25
|
+
data.call(mab)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
helpers Markaby
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class SinatraMarkabyTest < Test::Unit::TestCase
|
4
|
+
def markaby_app(&block)
|
5
|
+
mock_app {
|
6
|
+
use_in_file_templates!
|
7
|
+
helpers Sinatra::Markaby
|
8
|
+
set :views, File.dirname(__FILE__) + '/views'
|
9
|
+
get '/', &block
|
10
|
+
}
|
11
|
+
get '/'
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_renders_inline_strings
|
15
|
+
markaby_app { markaby 'mab.p "Hello shrimp!"' }
|
16
|
+
assert ok?
|
17
|
+
assert_equal "<p>Hello shrimp!</p>", body
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_renders_inline_blocks
|
21
|
+
markaby_app {
|
22
|
+
@name = "Frank & Mary"
|
23
|
+
markaby do |mab|
|
24
|
+
mab.p "Hello #{@name}!"
|
25
|
+
end
|
26
|
+
}
|
27
|
+
assert ok?
|
28
|
+
assert_equal "<p>Hello Frank & Mary!</p>", body
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_renders_markaby_files_in_views_path
|
32
|
+
markaby_app {
|
33
|
+
@name = "World"
|
34
|
+
markaby :hello
|
35
|
+
}
|
36
|
+
assert ok?
|
37
|
+
assert_equal "<p>Hello, World!</p>", body
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_renders_in_file_template
|
41
|
+
markaby_app {
|
42
|
+
@name = "Joe"
|
43
|
+
markaby :in_file
|
44
|
+
}
|
45
|
+
assert ok?
|
46
|
+
assert_equal "<p>Hey Joe</p>", body
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_raises_error_if_template_not_found
|
50
|
+
mock_app {
|
51
|
+
helpers Sinatra::Markaby
|
52
|
+
set :environment, :test
|
53
|
+
set :raise_errors, true
|
54
|
+
get('/') { markaby :no_such_template }
|
55
|
+
}
|
56
|
+
assert_raises(Errno::ENOENT) { get('/') }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
__END__
|
61
|
+
|
62
|
+
@@ in_file
|
63
|
+
mab.p "Hey #{@name}"
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'sinatra/test'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
require 'sinatra/markaby'
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
include Sinatra::Test
|
10
|
+
|
11
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
12
|
+
# given. Used in setup or individual spec methods to establish
|
13
|
+
# the application.
|
14
|
+
def mock_app(base=Sinatra::Base, &block)
|
15
|
+
@app = Sinatra.new(base, &block)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
mab.p "Hello, #{@name}!"
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sbfaulkner-sinatra-markaby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- S. Brent Faulkner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: markaby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Sinatra plugin to enable markaby (.mab) template rendering.
|
26
|
+
email: brentf@unwwwired.net
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.rdoc
|
37
|
+
- Rakefile
|
38
|
+
- VERSION.yml
|
39
|
+
- lib/sinatra/markaby.rb
|
40
|
+
- test/sinatra_markaby_test.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
- test/views/hello.mab
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/sbfaulkner/sinatra-markaby
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Sinatra plugin to enable markaby (.mab) template rendering.
|
69
|
+
test_files:
|
70
|
+
- test/sinatra_markaby_test.rb
|
71
|
+
- test/test_helper.rb
|