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