wbzyl-sinatra-rdiscount 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
+ pkg/*
1
2
  *.gem
data/README.markdown CHANGED
@@ -1,17 +1,18 @@
1
- # RDiscount Templates for Sinatra
1
+ # Extension providing RDiscount templates for Sinatra
2
2
 
3
- The *sinatra-rdiscount* gem is an extension for Sinatra.
4
- It provides a request-helper method named *rdiscount*
3
+ The *sinatra-rdiscount* gem is an extension for Sinatra
4
+ implemented as a gem.
5
+ It provides a request-helper method named `rdiscount`
5
6
  for rendering RDiscount templates.
6
7
 
7
- To use this extension, first install the gem on your system:
8
+ To use this extension, first install *sinatra-rdiscount* gem:
8
9
 
9
10
  git clone git://github.com/wbzyl/sinatra-rdiscount.git
10
11
  cd sinatra-rdiscount
11
12
  gem build sinatra-rdiscount
12
13
  sudo gem install sinatra-rdiscount
13
14
 
14
- Then create simple Sinatra application *app.rb*:
15
+ Then create a simple Sinatra application *app.rb*:
15
16
 
16
17
  require 'rubygems'
17
18
  require 'sinatra'
@@ -30,12 +31,11 @@ The result could be seen here: *http://localhost:4567*.
30
31
  Another example could be find in the *examples* directory.
31
32
 
32
33
 
33
- ## Views / Templates
34
+ ## Template Languages (*update to The Sinatra Book*)
34
35
 
35
36
  One important thing to remember is that you always have to reference
36
37
  templates and layouts with **symbols**, even if they’re in a subdirectory,
37
38
  for example `:'subdir/template'`.
38
-
39
39
  Rendering methods will render any strings passed to them directly.
40
40
 
41
41
 
@@ -55,17 +55,14 @@ renders template *./views/index.rdiscount*.
55
55
  If a layout named *layout.rdiscount* exists, it will be used each time
56
56
  a template is rendered.
57
57
 
58
- You can disable layouts by passing:
59
-
60
- :layout => false
61
-
62
- For example
58
+ You can disable layouts by passing `:layout => false`
59
+ to *rdiscount* helper. For example
63
60
 
64
61
  get '/' do
65
62
  rdiscount :index, :layout => false
66
63
  end
67
64
 
68
- You can set a different layout from the default with:
65
+ You can set a different layout from the default one with:
69
66
 
70
67
  get '/' do
71
68
  rdiscount :index, :layout => :application
data/Rakefile CHANGED
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require "rake/clean"
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |s|
10
+ s.name = "sinatra-rdiscount"
11
+ s.summary = "An extension providing RDiscount templates for Sinatra applications."
12
+ s.email = "matwb@univ.gda.pl"
13
+ s.homepage = "http://github.com/wbzyl/sinatra-rdiscount"
14
+ s.description = "An extension providing RDiscount templates for Sinatra applications."
15
+ s.authors = ["Włodek Bzyl"]
16
+
17
+ s.add_dependency 'rdiscount', '>=1.3.4'
18
+ s.add_dependency 'erubis', '>=2.6.4'
19
+ end
20
+ rescue LoadError
21
+ puts "Jeweler not available."
22
+ puts "Install it with:"
23
+ puts " sudo gem install technicalpickles-jeweler -s http://gems.github.com"
24
+ end
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib' << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ desc 'Install the package as a gem.'
33
+ task :install => [:clean, :build] do
34
+ gem = Dir['pkg/*.gem'].first
35
+ sh "sudo gem install --no-rdoc --no-ri --local #{gem}"
36
+ end
37
+
38
+ task :default => :test
data/examples/config.ru CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  require 'app'
4
4
 
5
- use Rack::Static,
6
- :urls => ["/stylesheets"],
7
- :root => "public"
5
+ use Rack::Static, :urls => ["/stylesheets"], :root => "public"
8
6
 
9
7
  run Sinatra::Application
@@ -1,11 +1,12 @@
1
+ require 'erubis'
2
+ require 'rdiscount'
3
+
1
4
  require 'sinatra/base'
2
5
 
3
6
  module Sinatra
4
7
  module RDiscountTemplate
5
8
 
6
9
  def rdiscount(template, options={}, locals={})
7
- require 'erubis' unless defined? ::Erubis::Eruby
8
- require 'rdiscount' unless defined? ::RDiscount
9
10
  render :rdiscount, template, options, locals
10
11
  end
11
12
 
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "sinatra-rdiscount"
5
- s.version = '0.0.6'
5
+ s.version = '0.0.8'
6
6
  s.date = '2009-03-31'
7
7
 
8
8
  s.summary = "RDiscount templates for Sinatra applications"
9
9
  s.email = "matwb@univ.gda.pl"
10
10
  s.homepage = "http://github.com/wbzyl/sinatra-rdiscount"
11
- s.description = "RDiscount templates for Sinatra applications"
11
+ s.description = ""
12
12
  s.authors = ["Włodek Bzyl"]
13
13
  s.files = %w{.gitignore
14
14
  sinatra-rdiscount.gemspec
@@ -16,7 +16,10 @@ Gem::Specification.new do |s|
16
16
  README.markdown
17
17
  LICENSE
18
18
  lib/sinatra/rdiscount.rb
19
- test/spec_sinatra_rdiscount.rb
19
+ test/test_helper.rb
20
+ test/sinatra_rdiscount_test.rb
21
+ test/views/hello.rdiscount
22
+ test/views/layout2.rdiscount
20
23
  examples/app.rb
21
24
  examples/config.ru
22
25
  examples/views/layout2.rdiscount
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SinatraRDiscountTest < Test::Unit::TestCase
4
+ include Sinatra::Test
5
+
6
+ def rdiscount_app(&block)
7
+ mock_app {
8
+ set :views, File.dirname(__FILE__) + '/views'
9
+ helpers Sinatra::RDiscountTemplate
10
+ set :show_exceptions, false
11
+ get '/', &block
12
+ }
13
+ get '/'
14
+ end
15
+
16
+ def test_renders_inline_strings
17
+ rdiscount_app { rdiscount 'hello world' }
18
+ assert ok?
19
+ assert_equal "<p>hello world</p>\n", body
20
+ end
21
+
22
+ def test_renders_inline_erb_string
23
+ rdiscount_app { rdiscount '{%= 1 + 1 %}' }
24
+ assert ok?
25
+ assert_equal "<p>2</p>\n", body
26
+ end
27
+
28
+ def test_renders_files_in_views_path
29
+ rdiscount_app { rdiscount :hello }
30
+ assert ok?
31
+ assert_equal "<h1>hello world</h1>\n", body
32
+ end
33
+
34
+ def test_takes_locals_option
35
+ rdiscount_app {
36
+ locals = {:foo => 'Bar'}
37
+ rdiscount "{%= foo %}", :locals => locals
38
+ }
39
+ assert ok?
40
+ assert_equal "<p>Bar</p>\n", body
41
+ end
42
+
43
+ def test_renders_with_inline_layouts
44
+ rdiscount_app {
45
+ rdiscount 'Sparta', :layout => 'THIS. IS. <%= yield.upcase %>'
46
+ }
47
+ assert ok?
48
+ assert_equal "THIS. IS. <P>SPARTA</P>\n", body
49
+ end
50
+
51
+ def test_renders_with_file_layouts
52
+ rdiscount_app {
53
+ rdiscount 'hello world', :layout => :layout2
54
+ }
55
+ assert ok?
56
+ assert_equal "erb layout\n<p>hello world</p>\n\n", body
57
+ end
58
+
59
+ def test_renders_erb_with_blocks
60
+ mock_app {
61
+ set :views, File.dirname(__FILE__) + '/views'
62
+ helpers Sinatra::RDiscountTemplate
63
+
64
+ def container
65
+ yield
66
+ end
67
+ def is;
68
+ "THIS. IS. SPARTA!"
69
+ end
70
+
71
+ get '/' do
72
+ rdiscount '{% container do %} {%= is %} {% end %}'
73
+ end
74
+ }
75
+
76
+ get '/'
77
+ assert ok?
78
+ assert_equal "<p> THIS. IS. SPARTA! </p>\n", body
79
+ end
80
+
81
+ def test_raises_error_if_template_not_found
82
+ mock_app {
83
+ set :views, File.dirname(__FILE__) + '/views'
84
+ helpers Sinatra::RDiscountTemplate
85
+ set :show_exceptions, false
86
+
87
+ get('/') { rdiscount :no_such_template }
88
+ }
89
+ assert_raise(Errno::ENOENT) { get('/') }
90
+ end
91
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'sinatra/test'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'sinatra/rdiscount'
7
+
8
+ require 'rdiscount'
9
+
10
+ class Test::Unit::TestCase
11
+ include Sinatra::Test
12
+
13
+ # Sets up a Sinatra::Base subclass defined with the block
14
+ # given. Used in setup or individual spec methods to establish
15
+ # the application.
16
+ def mock_app(base=Sinatra::Base, &block)
17
+ @app = Sinatra.new(base, &block)
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ # hello world
@@ -0,0 +1,2 @@
1
+ erb layout
2
+ <%= yield %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wbzyl-sinatra-rdiscount
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "W\xC5\x82odek Bzyl"
@@ -42,7 +42,7 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 2.6.4
44
44
  version:
45
- description: RDiscount templates for Sinatra applications
45
+ description: ""
46
46
  email: matwb@univ.gda.pl
47
47
  executables: []
48
48
 
@@ -57,7 +57,10 @@ files:
57
57
  - README.markdown
58
58
  - LICENSE
59
59
  - lib/sinatra/rdiscount.rb
60
- - test/spec_sinatra_rdiscount.rb
60
+ - test/test_helper.rb
61
+ - test/sinatra_rdiscount_test.rb
62
+ - test/views/hello.rdiscount
63
+ - test/views/layout2.rdiscount
61
64
  - examples/app.rb
62
65
  - examples/config.ru
63
66
  - examples/views/layout2.rdiscount
File without changes