cuba-contrib 3.0.0.rc1 → 3.0.0.rc2
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/README.markdown +4 -5
- data/cuba-contrib.gemspec +1 -1
- data/lib/cuba/contrib.rb +0 -1
- data/test/mote.rb +3 -3
- metadata +9 -14
- data/lib/cuba/contrib/rendering.rb +0 -49
- data/test/caching.rb +0 -17
- data/test/layout.rb +0 -16
- data/test/rendering.rb +0 -42
- data/test/test.erb +0 -1
data/README.markdown
CHANGED
@@ -117,17 +117,16 @@ that's exactly how the `markdown` helper is written in
|
|
117
117
|
`Cuba::TextHelpers`.
|
118
118
|
|
119
119
|
A more complicated plugin for example, will make use of
|
120
|
-
`Cuba
|
120
|
+
`Cuba.settings` to provide default values:
|
121
121
|
|
122
122
|
``` ruby
|
123
123
|
module Rendering
|
124
124
|
def self.setup(app)
|
125
|
-
app.
|
126
|
-
app.set :template_engine, "erb"
|
125
|
+
app.settings[:template_engine] = "erb"
|
127
126
|
end
|
128
127
|
|
129
128
|
def partial(template, locals = {})
|
130
|
-
render("#{template}.#{settings
|
129
|
+
render("#{template}.#{settings[:template_engine]}", locals)
|
131
130
|
end
|
132
131
|
end
|
133
132
|
|
@@ -139,4 +138,4 @@ This sample plugin actually resembles how `Cuba::Rendering` works.
|
|
139
138
|
[cuba]: http://cuba.is
|
140
139
|
[sites]: http://cuba.is/sites
|
141
140
|
[mote]: http://github.com/soveran/mote
|
142
|
-
[unix]: http://en.wikipedia.org/wiki/Unix_philosophy
|
141
|
+
[unix]: http://en.wikipedia.org/wiki/Unix_philosophy
|
data/cuba-contrib.gemspec
CHANGED
data/lib/cuba/contrib.rb
CHANGED
@@ -2,7 +2,6 @@ class Cuba
|
|
2
2
|
CONTRIB_ROOT = File.expand_path("../../", File.dirname(__FILE__))
|
3
3
|
|
4
4
|
autoload :Prelude, "cuba/contrib/prelude"
|
5
|
-
autoload :Rendering, "cuba/contrib/rendering"
|
6
5
|
autoload :Mote, "cuba/contrib/mote"
|
7
6
|
autoload :TextHelpers, "cuba/contrib/text_helpers"
|
8
7
|
autoload :FormHelpers, "cuba/contrib/form_helpers"
|
data/test/mote.rb
CHANGED
@@ -21,17 +21,17 @@ end
|
|
21
21
|
test do
|
22
22
|
_, _, body = Cuba.call({ "PATH_INFO" => "/", "SCRIPT_NAME" => "" })
|
23
23
|
|
24
|
-
assert_response body, ["<title>Hola</title>\n<h1>Home</h1
|
24
|
+
assert_response body, ["<title>Hola</title>\n<h1>Home</h1>\n\n"]
|
25
25
|
end
|
26
26
|
|
27
27
|
test do
|
28
28
|
_, _, body = Cuba.call({ "PATH_INFO" => "/frag", "SCRIPT_NAME" => "" })
|
29
29
|
|
30
|
-
assert_response body, ["<h1>Bar</h1
|
30
|
+
assert_response body, ["<h1>Bar</h1>\n"]
|
31
31
|
end
|
32
32
|
|
33
33
|
test do
|
34
34
|
_, _, body = Cuba.call({ "PATH_INFO" => "/abs_path", "SCRIPT_NAME" => "" })
|
35
35
|
|
36
|
-
assert_response body, ["<title>Absolute</title>\n<h1>Abs Path</h1
|
36
|
+
assert_response body, ["<title>Absolute</title>\n<h1>Abs Path</h1>\n\n"]
|
37
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cuba
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152117720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152117720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cutest
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152116800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152116800
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: capybara
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152116280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152116280
|
47
47
|
description: Includes various helper tools for Cuba.
|
48
48
|
email:
|
49
49
|
- me@cyrildavid.com
|
@@ -57,16 +57,11 @@ files:
|
|
57
57
|
- lib/cuba/contrib/form_helpers.rb
|
58
58
|
- lib/cuba/contrib/mote.rb
|
59
59
|
- lib/cuba/contrib/prelude.rb
|
60
|
-
- lib/cuba/contrib/rendering.rb
|
61
60
|
- lib/cuba/contrib/text_helpers.rb
|
62
61
|
- lib/cuba/contrib.rb
|
63
62
|
- cuba-contrib.gemspec
|
64
|
-
- test/caching.rb
|
65
63
|
- test/helper.rb
|
66
|
-
- test/layout.rb
|
67
64
|
- test/mote.rb
|
68
|
-
- test/rendering.rb
|
69
|
-
- test/test.erb
|
70
65
|
- test/text_helper.rb
|
71
66
|
- views/field.mote
|
72
67
|
- views/file.mote
|
@@ -95,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
90
|
version: 1.3.1
|
96
91
|
requirements: []
|
97
92
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.8.
|
93
|
+
rubygems_version: 1.8.16
|
99
94
|
signing_key:
|
100
95
|
specification_version: 3
|
101
96
|
summary: Cuba plugins and utilities.
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require "tilt"
|
2
|
-
|
3
|
-
class Cuba
|
4
|
-
module Rendering
|
5
|
-
def self.setup(app)
|
6
|
-
app.settings[:template_engine] = "erb"
|
7
|
-
app.settings[:views] = File.expand_path("views", Dir.pwd)
|
8
|
-
app.settings[:layout] = "layout"
|
9
|
-
end
|
10
|
-
|
11
|
-
def view(template, locals = {}, layout = settings[:layout])
|
12
|
-
partial(layout, { content: partial(template, locals) }.merge(locals))
|
13
|
-
end
|
14
|
-
|
15
|
-
def partial(template, locals = {})
|
16
|
-
render("#{settings[:views]}/#{template}.#{settings[:template_engine]}",
|
17
|
-
locals, default_encoding: Encoding.default_external)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Render any type of template file supported by Tilt.
|
21
|
-
#
|
22
|
-
# @example
|
23
|
-
#
|
24
|
-
# # Renders home, and is assumed to be HAML.
|
25
|
-
# render("home.haml")
|
26
|
-
#
|
27
|
-
# # Renders with some local variables
|
28
|
-
# render("home.haml", site_name: "My Site")
|
29
|
-
#
|
30
|
-
# # Renders with HAML options
|
31
|
-
# render("home.haml", {}, ugly: true, format: :html5)
|
32
|
-
#
|
33
|
-
# # Renders in layout
|
34
|
-
# render("layout.haml") { render("home.haml") }
|
35
|
-
#
|
36
|
-
def render(template, locals = {}, options = {}, &block)
|
37
|
-
_cache.fetch(template) {
|
38
|
-
Tilt.new(template, 1, options)
|
39
|
-
}.render(self, locals, &block)
|
40
|
-
end
|
41
|
-
|
42
|
-
# @private Used internally by #render to cache the
|
43
|
-
# Tilt templates.
|
44
|
-
def _cache
|
45
|
-
Thread.current[:_cache] ||= Tilt::Cache.new
|
46
|
-
end
|
47
|
-
private :_cache
|
48
|
-
end
|
49
|
-
end
|
data/test/caching.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
test "executes on true" do
|
4
|
-
Cuba.plugin Cuba::Rendering
|
5
|
-
|
6
|
-
Cuba.define do
|
7
|
-
on "foo/:i" do |i|
|
8
|
-
res.write render("test/test.erb", title: i)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
1000.times do |i|
|
13
|
-
_, _, resp = Cuba.call({ "PATH_INFO" => "/foo/#{i}", "SCRIPT_NAME" => "" })
|
14
|
-
end
|
15
|
-
|
16
|
-
assert_equal 1, Thread.current[:_cache].instance_variable_get(:@cache).size
|
17
|
-
end
|
data/test/layout.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
-
|
3
|
-
test "simple layout support" do
|
4
|
-
Cuba.plugin Cuba::Rendering
|
5
|
-
Cuba.define do
|
6
|
-
on true do
|
7
|
-
res.write render("test/fixtures/layout.erb") {
|
8
|
-
render("test/fixtures/content.erb")
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
_, _, resp = Cuba.call({})
|
14
|
-
|
15
|
-
assert_equal ["alfa beta\n\n"], resp.body
|
16
|
-
end
|
data/test/rendering.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
Cuba.plugin Cuba::Rendering
|
4
|
-
Cuba.settings[:views] = "./test/views"
|
5
|
-
|
6
|
-
Cuba.define do
|
7
|
-
on "home" do
|
8
|
-
res.write view("home", name: "Agent Smith", title: "Home")
|
9
|
-
end
|
10
|
-
|
11
|
-
on "about" do
|
12
|
-
res.write partial("about", title: "About Cuba")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
test "partial" do
|
17
|
-
_, _, body = Cuba.call({ "PATH_INFO" => "/about", "SCRIPT_NAME" => "/" })
|
18
|
-
|
19
|
-
assert_response body, ["<h1>About Cuba</h1>"]
|
20
|
-
end
|
21
|
-
|
22
|
-
test "view" do
|
23
|
-
_, _, body = Cuba.call({ "PATH_INFO" => "/home", "SCRIPT_NAME" => "/" })
|
24
|
-
|
25
|
-
assert_response body, ["<title>Cuba: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"]
|
26
|
-
end
|
27
|
-
|
28
|
-
test "partial with str as engine" do
|
29
|
-
Cuba.settings[:template_engine] = "str"
|
30
|
-
|
31
|
-
_, _, body = Cuba.call({ "PATH_INFO" => "/about", "SCRIPT_NAME" => "/" })
|
32
|
-
|
33
|
-
assert_response body, ["<h1>About Cuba</h1>"]
|
34
|
-
end
|
35
|
-
|
36
|
-
test "view with str as engine" do
|
37
|
-
Cuba.settings[:template_engine] = "str"
|
38
|
-
|
39
|
-
_, _, body = Cuba.call({ "PATH_INFO" => "/home", "SCRIPT_NAME" => "/" })
|
40
|
-
|
41
|
-
assert_response body, ["<title>Cuba: Home</title>\n<h1>Home</h1>\n<p>Hello Agent Smith</p>"]
|
42
|
-
end
|
data/test/test.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= title %>
|