sinatra-maruku 0.9.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg
2
+ *~
3
+ \#*
4
+ .\#*
5
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2008 Wlodek Bzyl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,84 @@
1
+ # Sinatra Maruku Extension for Sinatra v0.9.4
2
+
3
+ The *sinatra-maruku* extension provides `maruku` helper method
4
+ for rendering Maruku templates.
5
+
6
+ To install it, run:
7
+
8
+ sudo gem install -v0.9.4.0 sinatra-maruku
9
+
10
+ To test it, create a simple Sinatra application:
11
+
12
+ # app.rb
13
+ require 'rubygems'
14
+ require 'sinatra'
15
+
16
+ require 'sinatra/maruku'
17
+
18
+ get "/" do
19
+ maruku "# Hello Maruku"
20
+ end
21
+
22
+ and run it with:
23
+
24
+ ruby app.rb
25
+
26
+ The result could be seen at *http://localhost:4567*.
27
+
28
+ Another example could be find in the *examples* directory.
29
+ Run it with:
30
+
31
+ rackup -p 4567 config.ru
32
+
33
+ and visit *http://localhost:4567* to contemplate the sheer
34
+ beauty of rendered text written in Maruku notation.
35
+
36
+
37
+ ## Two links to Maruku related material
38
+
39
+ * [Maruku features](http://maruku.rubyforge.org/maruku.html)
40
+ * [Literate Maruku](http://www.slideshare.net/schmidt/literate-maruku)
41
+
42
+
43
+ ## Template Languages (*update to The Sinatra Book*)
44
+
45
+ ### Maruku Templates
46
+
47
+ This helper method:
48
+
49
+ get '/' do
50
+ maruku :index
51
+ end
52
+
53
+ renders template *./views/index.maruku*.
54
+
55
+ If a layout named *layout.maruku* exists, it will be used each time
56
+ a template is rendered.
57
+
58
+ You can disable layouts by passing `:layout => false`
59
+ to *maruku* helper. For example
60
+
61
+ get '/' do
62
+ maruku :index, :layout => false
63
+ end
64
+
65
+ You can set a different layout from the default one with:
66
+
67
+ get '/' do
68
+ maruku :index, :layout => :application
69
+ end
70
+
71
+ This renders *./views/index.maruku* template
72
+ within *./views/application.maruku* layout.
73
+
74
+
75
+ ## Sample layout for Maruku templates
76
+
77
+ CSS: /stylesheets/application.css /stylesheets/print.css
78
+ Lang: pl
79
+ Title: Hello Maruku
80
+ LaTeX preamble: preamble.tex
81
+
82
+ # Hello Maruku {.header}
83
+
84
+ <%= yield %>
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require "rake/clean"
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "sinatra-maruku"
9
+ gem.summary = "An extension providing Maruku templates for Sinatra applications."
10
+ gem.email = "matwb@univ.gda.pl"
11
+ gem.homepage = "http://github.com/wbzyl/sinatra-maruku"
12
+ gem.description = gem.description
13
+ gem.authors = ["Wlodek Bzyl"]
14
+
15
+ gem.add_runtime_dependency 'sinatra', '=0.9.4'
16
+ gem.add_runtime_dependency 'maruku', '>=0.6.0'
17
+
18
+ gem.add_development_dependency 'rack', '>=1.0.0'
19
+ gem.add_development_dependency 'rack-test', '>=0.5.3'
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler not available."
24
+ puts "Install it with:"
25
+ puts " sudo gem install jeweler"
26
+ end
27
+
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'lib' << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 9
4
+ :patch: 4
5
+ :build: 0
data/examples/app.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'sinatra/maruku'
4
+
5
+ get "/" do
6
+ #maruku :hello, :layout => false
7
+ maruku :index
8
+ end
@@ -0,0 +1,4 @@
1
+ # run it: rackup config.ru -p 4567
2
+
3
+ require 'app'
4
+ run Sinatra::Application
data/examples/mapp.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+ require 'sinatra/maruku'
4
+
5
+ require 'rack'
6
+
7
+ class MApp < Sinatra::Base
8
+ helpers Sinatra::Maruku
9
+
10
+ get '/' do
11
+ maruku "## hello form modular app"
12
+ end
13
+ end
14
+
15
+ Rack::Handler::Thin.run MApp.new, :Port => 4567
File without changes
@@ -0,0 +1,23 @@
1
+ html {
2
+ margin: 0;
3
+ padding: 0;
4
+ background-color: #B5052E;
5
+ line-height: 1.6;
6
+ }
7
+
8
+ body {
9
+ margin: 1em auto 1em auto;
10
+ padding: 1em 2em 2em 1em;
11
+ width: 760px;
12
+ border: 1px solid black;
13
+ background-color: #E8DDCB;
14
+ }
15
+
16
+ pre {
17
+ padding: 0.5em 0 0.5em 2em;
18
+ background-color: #D7D3C1;
19
+ }
20
+
21
+ h1, h2, h3 {
22
+ color: #B5052E;
23
+ }
File without changes
@@ -0,0 +1,32 @@
1
+ Maruku features
2
+ ===============
3
+
4
+ Maruku allows you to write in an easy-to-read-and-write syntax, like this:
5
+
6
+ > [This document in Markdown][this_md]
7
+
8
+ Then it can be translated to HTML:
9
+
10
+ > [This document in HTML][this_html]
11
+
12
+ or LaTeX, which is then converted to PDF:
13
+
14
+ > [This document in PDF][this_pdf]
15
+
16
+ Maruku implements:
17
+
18
+ * the original [Markdown syntax][markdown_html]
19
+ ([HTML][markdown_html] or [PDF][markdown_pdf]), translated by Maruku).
20
+
21
+ * all the improvements in PHP Markdown Extra.
22
+
23
+ * a new [meta-data syntax][meta_data_proposal]
24
+
25
+ [markdown_html]: http://maruku.rubyforge.org/markdown_syntax.html
26
+ [markdown_pdf]: http://maruku.rubyforge.org/markdown_syntax.pdf
27
+ [this_md]: http://maruku.rubyforge.org/maruku.md
28
+ [this_html]: http://maruku.rubyforge.org/maruku.html
29
+ [this_pdf]: http://maruku.rubyforge.org/maruku.pdf
30
+ [Andrea Censi]: http://www.dis.uniroma1.it/~acensi/
31
+
32
+ [meta_data_proposal]: http://maruku.rubyforge.org/proposal.html
@@ -0,0 +1,9 @@
1
+ CSS: /stylesheets/application.css /stylesheets/print.css
2
+ Javascript: /javascriprs/application.js
3
+ Lang: pl
4
+ Title: Hello Maruku
5
+ LaTeX preamble: preamble.tex
6
+
7
+ # Hello Maruku {.header}
8
+
9
+ <%= yield %>
@@ -0,0 +1,27 @@
1
+ require 'maruku'
2
+ require 'sinatra/base'
3
+
4
+ module Sinatra
5
+ module Maruku
6
+
7
+ def maruku(template, options={}, locals={})
8
+ render :maruku, template, options, locals
9
+ end
10
+
11
+ private
12
+
13
+ def render_maruku(template, data, options, locals, &block)
14
+ maruku_src = render_erb(template, data, options, locals, &block)
15
+ instance = ::Maruku.new(maruku_src, options)
16
+ if block_given?
17
+ # render layout
18
+ instance.to_html_document
19
+ else
20
+ # render template
21
+ instance.to_html
22
+ end
23
+ end
24
+ end
25
+
26
+ helpers Maruku
27
+ end
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra-maruku}
8
+ s.version = "0.9.4.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Wlodek Bzyl"]
12
+ s.date = %q{2010-02-08}
13
+ s.description = %q{}
14
+ s.email = %q{matwb@univ.gda.pl}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.markdown",
23
+ "Rakefile",
24
+ "VERSION.yml",
25
+ "examples/app.rb",
26
+ "examples/config.ru",
27
+ "examples/mapp.rb",
28
+ "examples/public/javascripts/application.js",
29
+ "examples/public/stylesheets/application.css",
30
+ "examples/public/stylesheets/print.css",
31
+ "examples/views/index.maruku",
32
+ "examples/views/layout.maruku",
33
+ "lib/sinatra/maruku.rb",
34
+ "sinatra-maruku.gemspec",
35
+ "test/sinatra_maruku_test.rb",
36
+ "test/test_helper.rb",
37
+ "test/views/hello.maruku",
38
+ "test/views/layout2.maruku"
39
+ ]
40
+ s.homepage = %q{http://github.com/wbzyl/sinatra-maruku}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.5}
44
+ s.summary = %q{An extension providing Maruku templates for Sinatra applications.}
45
+ s.test_files = [
46
+ "test/test_helper.rb",
47
+ "test/sinatra_maruku_test.rb",
48
+ "examples/mapp.rb",
49
+ "examples/app.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ s.add_runtime_dependency(%q<sinatra>, ["= 0.9.4"])
58
+ s.add_runtime_dependency(%q<maruku>, [">= 0.6.0"])
59
+ s.add_development_dependency(%q<rack>, [">= 1.0.0"])
60
+ s.add_development_dependency(%q<rack-test>, [">= 0.5.3"])
61
+ else
62
+ s.add_dependency(%q<sinatra>, ["= 0.9.4"])
63
+ s.add_dependency(%q<maruku>, [">= 0.6.0"])
64
+ s.add_dependency(%q<rack>, [">= 1.0.0"])
65
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<sinatra>, ["= 0.9.4"])
69
+ s.add_dependency(%q<maruku>, [">= 0.6.0"])
70
+ s.add_dependency(%q<rack>, [">= 1.0.0"])
71
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
72
+ end
73
+ end
74
+
@@ -0,0 +1,91 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class SinatraMarukuTest < Test::Unit::TestCase
4
+ include Rack::Test::Methods
5
+
6
+ def maruku_app(&block)
7
+ mock_app {
8
+ set :views, File.dirname(__FILE__) + '/views'
9
+ helpers Sinatra::Maruku
10
+ set :show_exceptions, false
11
+ get '/', &block
12
+ }
13
+ get '/'
14
+ end
15
+
16
+ def test_renders_inline_strings
17
+ maruku_app { maruku 'hello world' }
18
+ assert last_response.ok?
19
+ assert_equal "<p>hello world</p>", last_response.body
20
+ end
21
+
22
+ def test_renders_inline_erb_string
23
+ maruku_app { maruku '<%= 1 + 1 %>' }
24
+ assert last_response.ok?
25
+ assert_equal "<p>2</p>", last_response.body
26
+ end
27
+
28
+ def test_renders_files_in_views_path
29
+ maruku_app { maruku :hello }
30
+ assert last_response.ok?
31
+ assert_equal "<h1 id='hello_world'>hello world</h1>", last_response.body
32
+ end
33
+
34
+ def test_takes_locals_option
35
+ maruku_app {
36
+ locals = {:foo => 'Bar'}
37
+ maruku "<%= foo %>", :locals => locals
38
+ }
39
+ assert last_response.ok?
40
+ assert_equal "<p>Bar</p>", last_response.body
41
+ end
42
+
43
+ def test_renders_with_inline_layouts
44
+ maruku_app {
45
+ maruku 'Sparta', :layout => 'THIS. IS. <%= yield.upcase %>'
46
+ }
47
+ assert last_response.ok?
48
+ assert_equal "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC\n \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\"\n \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\">\n<html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>\n<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title></title></head>\n<body>\n<p>THIS. IS. <P>SPARTA</P></p>\n</body></html>", last_response.body
49
+ end
50
+
51
+ def test_renders_with_file_layouts
52
+ maruku_app {
53
+ maruku 'hello world', :layout => :layout2
54
+ }
55
+ assert last_response.ok?
56
+ assert_equal "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html PUBLIC\n \"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN\"\n \"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd\">\n<html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>\n<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title></title></head>\n<body>\n<p>erb layout <p>hello world</p></p>\n</body></html>", last_response.body
57
+ end
58
+
59
+ def test_renders_erb_with_blocks
60
+ mock_app {
61
+ set :views, File.dirname(__FILE__) + '/views'
62
+ helpers Sinatra::Maruku
63
+
64
+ def container
65
+ yield
66
+ end
67
+ def is
68
+ "THIS. IS. SPARTA!"
69
+ end
70
+
71
+ get '/' do
72
+ maruku '<% container do %> <%= is %> <% end %>'
73
+ end
74
+ }
75
+
76
+ get '/'
77
+ assert last_response.ok?
78
+ assert_equal "<p>THIS. IS. SPARTA!</p>", last_response.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::Maruku
85
+ set :show_exceptions, false
86
+
87
+ get('/') { maruku :no_such_template }
88
+ }
89
+ assert_raise(Errno::ENOENT) { get('/') }
90
+ end
91
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'rack/test'
4
+
5
+ path = File.expand_path("../lib" + File.dirname(__FILE__))
6
+ $:.unshift(path) unless $:.include?(path)
7
+
8
+ require 'sinatra/maruku'
9
+
10
+ class Test::Unit::TestCase
11
+ include Rack::Test::Methods
12
+
13
+ attr_reader :app
14
+
15
+ # Sets up a Sinatra::Base subclass defined with the block
16
+ # given. Used in setup or individual spec methods to establish
17
+ # the application.
18
+ def mock_app(base=Sinatra::Base, &block)
19
+ @app = Sinatra.new(base, &block)
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ # hello world
@@ -0,0 +1,2 @@
1
+ erb layout
2
+ <%= yield %>
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-maruku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Wlodek Bzyl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-08 00:00:00 +01: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.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: maruku
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rack-test
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.5.3
54
+ version:
55
+ description: ""
56
+ email: matwb@univ.gda.pl
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.markdown
64
+ files:
65
+ - .gitignore
66
+ - LICENSE
67
+ - README.markdown
68
+ - Rakefile
69
+ - VERSION.yml
70
+ - examples/app.rb
71
+ - examples/config.ru
72
+ - examples/mapp.rb
73
+ - examples/public/javascripts/application.js
74
+ - examples/public/stylesheets/application.css
75
+ - examples/public/stylesheets/print.css
76
+ - examples/views/index.maruku
77
+ - examples/views/layout.maruku
78
+ - lib/sinatra/maruku.rb
79
+ - sinatra-maruku.gemspec
80
+ - test/sinatra_maruku_test.rb
81
+ - test/test_helper.rb
82
+ - test/views/hello.maruku
83
+ - test/views/layout2.maruku
84
+ has_rdoc: true
85
+ homepage: http://github.com/wbzyl/sinatra-maruku
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.5
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: An extension providing Maruku templates for Sinatra applications.
112
+ test_files:
113
+ - test/test_helper.rb
114
+ - test/sinatra_maruku_test.rb
115
+ - examples/mapp.rb
116
+ - examples/app.rb