mote-render 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d58f145229d11c826d348a7c9029f55ddadc2255
4
+ data.tar.gz: 4806a2c6136d19f669e092594702596d15580cc8
5
+ SHA512:
6
+ metadata.gz: ebf30bde402675f07583ddfaab987334594ac97d353e68e66b0464ea3e6013f40d6ae795a7161cd28390fccccd2aca6ea4a76753253f341a17472a6170217721
7
+ data.tar.gz: e1e1321486a2c6f04d39f1a19c9dc44079f5b203bd4ec76de61309d8f118297a6461d887f24273332412a7a9763fdfe7d56353a826a7e1969b0502ceb8692226
data/.gems ADDED
@@ -0,0 +1,4 @@
1
+ cuba -v 3.1.1
2
+ cutest -v 1.2.1
3
+ mote -v 1.1.2
4
+ rack-test -v 0.6.2
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Francesco Rodríguez, Mayn Kjær
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ mote-render
2
+ ===========
3
+
4
+ Mote plugin for Cuba. This plugin was extracted from the
5
+ [cuba-contrib][cuba-contrib] gem, made by [cyx][cyx].
6
+
7
+ Usage
8
+ -----
9
+
10
+ To use Mote, you need to load the `Mote::Render` plugin as shown below:
11
+
12
+ ```ruby
13
+ require "mote/render"
14
+
15
+ Cuba.plugin(Mote::Render)
16
+ ```
17
+
18
+ `Mote::Render` provides three helper methods for rendering templates:
19
+ `partial`, `view` and `render`.
20
+
21
+ ```ruby
22
+ Cuba.define do
23
+ on "about" do
24
+ # `partial` renders a template without a layout.
25
+ res.write partial("about")
26
+ end
27
+
28
+ on "home" do
29
+ # `view` renders a template within a layout.
30
+ res.write view("about")
31
+ end
32
+
33
+ on "contact" do
34
+ # `render` is a shortcut to `res.write view(...)`
35
+ render("contact")
36
+ end
37
+ end
38
+ ```
39
+
40
+ By default, `Mote::Render` assumes that all view templates are placed
41
+ in a folder named `views` and that they use the `.mote` extension. Also
42
+ for `view` and `render` methods, it assumes that the layout template is
43
+ called `layout.mote`.
44
+
45
+ The defaults can be changed through the `Cuba.settings` method:
46
+
47
+ ```ruby
48
+ Cuba.settings[:mote][:views] = "./views/admin/"
49
+ Cuba.settings[:mote][:layout] = "admin"
50
+ ```
51
+
52
+ ### Layouts
53
+
54
+ To render inner content into a layout, use the `{{ content }}` tag.
55
+
56
+ ```html
57
+ <html>
58
+ <head>
59
+ <title>Mote Layout</title>
60
+ </head>
61
+ <body>
62
+ <h1>Hello, mote!</h1>
63
+ {{ content }}
64
+ </body>
65
+ </html>
66
+ ```
67
+
68
+ ### Helpers
69
+
70
+ You can use the `app` variable to access the application helpers.
71
+
72
+ ```ruby
73
+ Cuba.define do
74
+ def h(unsafe)
75
+ ...
76
+ end
77
+ end
78
+ ```
79
+
80
+ ```html
81
+ <h1>{{ app.h("unsafe") }}</h1>
82
+
83
+ {{ app.partial("list") }}
84
+ ```
85
+
86
+ Installation
87
+ ------------
88
+
89
+ ```
90
+ $ gem install mote-render
91
+ ```
92
+
93
+ [cuba]: https://github.com/soveran/cuba
94
+ [cuba-contrib]: https://github.com/cyx/cuba-contrib
95
+ [cyx]: https://github.com/cyx
96
+ [mote]: https://github.com/soveran/mote
@@ -0,0 +1,29 @@
1
+ require "mote"
2
+
3
+ module Mote::Render
4
+ include Mote::Helpers
5
+
6
+ def self.setup(app)
7
+ app.settings[:mote] ||= {}
8
+ app.settings[:mote][:views] ||= File.expand_path("views", Dir.pwd)
9
+ app.settings[:mote][:layout] ||= "layout"
10
+ end
11
+
12
+ def render(template, locals = {}, layout = settings[:mote][:layout])
13
+ res.write view(template, locals, layout)
14
+ end
15
+
16
+ def view(template, locals = {}, layout = settings[:mote][:layout])
17
+ partial(layout, locals.merge(content: partial(template, locals)))
18
+ end
19
+
20
+ def partial(template, locals = {})
21
+ mote(mote_path(template), locals.merge(app: self), TOPLEVEL_BINDING)
22
+ end
23
+
24
+ def mote_path(template)
25
+ return template if template.end_with?(".mote")
26
+
27
+ File.join(settings[:mote][:views], "#{template}.mote")
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "mote-render"
3
+ s.version = "1.0.0"
4
+ s.summary = "Mote plugin for Cuba."
5
+ s.description = s.summary
6
+ s.authors = ["Cyril David", "Francesco Rodríguez", "Mayn Kjær"]
7
+ s.email = ["frodsan@me.com", "mayn.kjaer@gmail.com"]
8
+ s.homepage = "https://github.com/frodsan/mote-render"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_dependency "mote"
14
+ s.add_development_dependency "cuba"
15
+ s.add_development_dependency "cutest"
16
+ end
@@ -0,0 +1 @@
1
+ <h1>Custom</h1>
@@ -0,0 +1,2 @@
1
+ <title>{{ title }}</title>
2
+ {{ content }}
data/test/render.rb ADDED
@@ -0,0 +1,77 @@
1
+ require "cuba/test"
2
+ require_relative "../lib/mote/render"
3
+
4
+ Cuba.plugin(Mote::Render)
5
+ Cuba.settings[:mote][:views] = "./test/views"
6
+
7
+ Cuba.define do
8
+ def name
9
+ "App"
10
+ end
11
+
12
+ on "partial" do
13
+ res.write partial("home")
14
+ end
15
+
16
+ on "view" do
17
+ res.write view("home", title: "Hello")
18
+ end
19
+
20
+ on "render" do
21
+ render("home", title: "Hola")
22
+ end
23
+
24
+ on "context" do
25
+ res.write partial("context")
26
+ end
27
+
28
+ on "absolute" do
29
+ render("./test/custom_views/custom.mote", title: "Custom")
30
+ end
31
+
32
+ on "absolute_layout" do
33
+ render("./test/custom_views/custom.mote", title: "Custom Layout")
34
+ end
35
+ end
36
+
37
+ scope do
38
+ test "view renders view with layout" do
39
+ expected = "<title>Hello</title>\n<h1>Home</h1>"
40
+
41
+ get "/view"
42
+
43
+ assert last_response.body[expected]
44
+ end
45
+
46
+ test "partial renders view without layout" do
47
+ get "/partial"
48
+
49
+ assert last_response.body["<h1>Home</h1>"]
50
+ end
51
+
52
+ test "render renders view with layout" do
53
+ get "/render"
54
+
55
+ assert last_response.body["<title>Hola</title>\n<h1>Home</h1>"]
56
+ end
57
+
58
+ test "access to application context" do
59
+ get "/context"
60
+
61
+ assert last_response.body["App"]
62
+ end
63
+
64
+ test "use of absolute path for template" do
65
+ get "/absolute"
66
+
67
+ assert last_response.body["<title>Custom</title>\n<h1>Custom</h1>"]
68
+ end
69
+
70
+ test "use of absolute path for layout" do
71
+ Cuba.settings[:mote][:layout] = "./test/custom_views/layout.mote"
72
+
73
+ get "/absolute_layout"
74
+
75
+ assert last_response.body["<title>Custom Layout</title>\n<h1>Custom</h1>"]
76
+ end
77
+ end
@@ -0,0 +1 @@
1
+ {{ app.name }}
@@ -0,0 +1 @@
1
+ <h1>Home</h1>
@@ -0,0 +1,2 @@
1
+ <title>{{ title }}</title>
2
+ {{ content }}
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mote-render
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril David
8
+ - Francesco Rodríguez
9
+ - Mayn Kjær
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-06-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mote
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: cuba
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: cutest
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description: Mote plugin for Cuba.
58
+ email:
59
+ - frodsan@me.com
60
+ - mayn.kjaer@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gems
66
+ - LICENSE
67
+ - README.md
68
+ - lib/mote/render.rb
69
+ - mote-render.gemspec
70
+ - test/custom_views/custom.mote
71
+ - test/custom_views/layout.mote
72
+ - test/render.rb
73
+ - test/views/context.mote
74
+ - test/views/home.mote
75
+ - test/views/layout.mote
76
+ homepage: https://github.com/frodsan/mote-render
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.14
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Mote plugin for Cuba.
100
+ test_files: []