wbzyl-sinatra-maruku 0.0.4

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
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,90 @@
1
+ # Extension providing Maruku templates for Sinatra apps
2
+
3
+ The gem provides a request-helper method named `maruku`
4
+ for rendering Maruku templates.
5
+
6
+ A few links:
7
+
8
+ * [Maruku features](http://maruku.rubyforge.org/maruku.html)
9
+ * [Literate Maruku](http://www.slideshare.net/schmidt/literate-maruku)
10
+
11
+ Testing Rack apps:
12
+
13
+ * Bryan Helmkamp, [Rack::Test released: Simply test any Rack-compatible
14
+ app](http://www.brynary.com/2009/3/5/rack-test-released-a-simple-testing-api-for-rack-based-frameworks-and-apps)
15
+ * [rack-test](http://github.com/brynary/rack-test/)
16
+
17
+ To use this extension, first install the *sinatra-maruku* gem:
18
+
19
+ git clone git://github.com/wbzyl/sinatra-maruku.git
20
+ cd sinatra-maruku
21
+ gem build sinatra-maruku
22
+ sudo gem install sinatra-maruku
23
+
24
+ Then create a simple Sinatra application *app.rb*:
25
+
26
+ require 'rubygems'
27
+ require 'sinatra'
28
+ require 'sinatra/maruku'
29
+
30
+ get "/" do
31
+ maruku "# Hello Maruku"
32
+ end
33
+
34
+ and run the above code:
35
+
36
+ ruby app.rb
37
+
38
+ The result could be seen here: *http://localhost:4567*.
39
+
40
+ Another example could be find in the *examples* directory.
41
+ Run it with:
42
+
43
+ rackup -p 4567 config.ru
44
+
45
+ Now, visit the following url *http://localhost:4567/hello*
46
+ and contemplate the sheer beauty of the rendered code.
47
+
48
+
49
+ ## Template Languages (*update to The Sinatra Book*)
50
+
51
+ ### Maruku Templates
52
+
53
+ This helper method:
54
+
55
+ get '/' do
56
+ maruku :index
57
+ end
58
+
59
+ renders template *./views/index.maruku*.
60
+
61
+ If a layout named *layout.maruku* exists, it will be used each time
62
+ a template is rendered.
63
+
64
+ You can disable layouts by passing `:layout => false`
65
+ to *maruku* helper. For example
66
+
67
+ get '/' do
68
+ maruku :index, :layout => false
69
+ end
70
+
71
+ You can set a different layout from the default one with:
72
+
73
+ get '/' do
74
+ maruku :index, :layout => :application
75
+ end
76
+
77
+ This renders *./views/index.maruku* template
78
+ within *./views/application.maruku* layout.
79
+
80
+
81
+ ## Sample layout for Maruku templates
82
+
83
+ CSS: /stylesheets/application.css /stylesheets/print.css
84
+ Lang: pl
85
+ Title: Hello Maruku
86
+ LaTeX preamble: preamble.tex
87
+
88
+ # Hello Maruku {.header}
89
+
90
+ <%= yield %>
data/Rakefile ADDED
@@ -0,0 +1,37 @@
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-maruku"
11
+ s.summary = "An extension providing Maruku templates for Sinatra applications."
12
+ s.email = "matwb@univ.gda.pl"
13
+ s.homepage = "http://github.com/wbzyl/sinatra-maruku"
14
+ s.description = "An extension providing Maruku templates for Sinatra applications."
15
+ s.authors = ["Włodek Bzyl"]
16
+
17
+ s.add_dependency 'maruku', '>=0.6.0'
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler not available."
21
+ puts "Install it with:"
22
+ puts " sudo gem install technicalpickles-jeweler -s http://gems.github.com"
23
+ end
24
+
25
+ Rake::TestTask.new(:test) do |t|
26
+ t.libs << 'lib' << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ desc 'Install the package as a gem.'
32
+ task :install => [:clean, :build] do
33
+ gem = Dir['pkg/*.gem'].first
34
+ sh "sudo gem install --no-rdoc --no-ri --local #{gem}"
35
+ end
36
+
37
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 4
data/examples/app.rb ADDED
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'sinatra'
5
+ require 'sinatra/maruku'
6
+
7
+ get "/" do
8
+ #maruku :hello, :layout => false
9
+ maruku :index
10
+ end
@@ -0,0 +1,7 @@
1
+ # run with: thin --rackup config.ru -p 4567 start
2
+
3
+ require 'app'
4
+
5
+ use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
6
+
7
+ 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,24 @@
1
+ require 'maruku'
2
+ require 'sinatra/base'
3
+
4
+ module Sinatra
5
+ module Maruku
6
+ def maruku(template, options={}, locals={})
7
+ render :maruku, template, options, locals
8
+ end
9
+
10
+ private
11
+ def render_maruku(template, data, options, locals, &block)
12
+ maruku_src = render_erb(template, data, options, locals, &block)
13
+ instance = ::Maruku.new(maruku_src, options)
14
+ if block_given?
15
+ # render layout
16
+ instance.to_html_document
17
+ else
18
+ # render template
19
+ instance.to_html
20
+ end
21
+ end
22
+ end
23
+ helpers Maruku
24
+ end
@@ -0,0 +1,61 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{sinatra-maruku}
5
+ s.version = "0.0.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["W\305\202odek Bzyl"]
9
+ s.date = %q{2009-05-19}
10
+ s.description = %q{An extension providing Maruku templates for Sinatra applications.}
11
+ s.email = %q{matwb@univ.gda.pl}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.markdown"
15
+ ]
16
+ s.files = [
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "VERSION.yml",
22
+ "examples/app.rb",
23
+ "examples/config.ru",
24
+ "examples/mapp.rb",
25
+ "examples/public/javascripts/application.js",
26
+ "examples/public/stylesheets/application.css",
27
+ "examples/public/stylesheets/print.css",
28
+ "examples/views/index.maruku",
29
+ "examples/views/layout.maruku",
30
+ "lib/sinatra/maruku.rb",
31
+ "sinatra-maruku.gemspec",
32
+ "test/sinatra_maruku_test.rb",
33
+ "test/test_helper.rb",
34
+ "test/views/hello.maruku",
35
+ "test/views/layout2.maruku"
36
+ ]
37
+ s.homepage = %q{http://github.com/wbzyl/sinatra-maruku}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.3}
41
+ s.summary = %q{An extension providing Maruku templates for Sinatra applications.}
42
+ s.test_files = [
43
+ "test/test_helper.rb",
44
+ "test/sinatra_maruku_test.rb",
45
+ "examples/mapp.rb",
46
+ "examples/app.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<maruku>, [">= 0.6.0"])
55
+ else
56
+ s.add_dependency(%q<maruku>, [">= 0.6.0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<maruku>, [">= 0.6.0"])
60
+ end
61
+ end
@@ -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
+ #ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'rack/test'
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
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,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wbzyl-sinatra-maruku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - "W\xC5\x82odek Bzyl"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-19 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: maruku
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.0
24
+ version:
25
+ description: An extension providing Maruku templates for Sinatra applications.
26
+ email: matwb@univ.gda.pl
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.markdown
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.markdown
38
+ - Rakefile
39
+ - VERSION.yml
40
+ - examples/app.rb
41
+ - examples/config.ru
42
+ - examples/mapp.rb
43
+ - examples/public/javascripts/application.js
44
+ - examples/public/stylesheets/application.css
45
+ - examples/public/stylesheets/print.css
46
+ - examples/views/index.maruku
47
+ - examples/views/layout.maruku
48
+ - lib/sinatra/maruku.rb
49
+ - sinatra-maruku.gemspec
50
+ - test/sinatra_maruku_test.rb
51
+ - test/test_helper.rb
52
+ - test/views/hello.maruku
53
+ - test/views/layout2.maruku
54
+ has_rdoc: false
55
+ homepage: http://github.com/wbzyl/sinatra-maruku
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.2.0
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: An extension providing Maruku templates for Sinatra applications.
80
+ test_files:
81
+ - test/test_helper.rb
82
+ - test/sinatra_maruku_test.rb
83
+ - examples/mapp.rb
84
+ - examples/app.rb