cuba-contrib 3.1.0.rc2 → 3.1.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.
@@ -3,7 +3,7 @@
3
3
  [Cuba][cuba] is probably one of the tiniest rack-based micro
4
4
  frameworks around. Weighing in at only __138 LOC__, it has proven
5
5
  itself to be a very resilient tool in various web application domains.
6
- Check [the list of sites][sites] built using Cuba in order to
6
+ Check [the list of sites][cuba] built using Cuba in order to
7
7
  grasp the endless possibilities.
8
8
 
9
9
  ## STEP 1: Cuba::Prelude
@@ -61,6 +61,7 @@ We prefer to use our home-grown templating engine called
61
61
  ``` ruby
62
62
  require "cuba"
63
63
  require "cuba/contrib"
64
+ require "mote"
64
65
 
65
66
  Cuba.plugin Cuba::Mote
66
67
 
@@ -72,20 +73,29 @@ Cuba.define do
72
73
  on "about" do
73
74
  res.write partial("about")
74
75
  end
76
+
77
+ # Or you can use `render` as a shortcut to `res.write view(...)`.
78
+ on "contact" do
79
+ render("contact")
80
+ end
75
81
  end
76
82
  ```
77
83
 
78
84
  This assumes that you have a `views` folder, containing a `home.mote`
79
- and an `about.mote`.
85
+ and an `about.mote`. Your layout defaults to `layout.mote`.
80
86
 
81
87
  ### Classic templating needs
82
88
 
89
+ **Note**: as of Cuba 3.0, the plugin architecture of `cuba-contrib` has
90
+ been merged into the core codebase. The following example should work with
91
+ Cuba 3.0 without even requiring `cuba-contrib`.
92
+
83
93
  ``` ruby
84
94
  require "cuba"
85
- require "cuba/contrib"
95
+ require "cuba/render"
86
96
 
87
- Cuba.plugin Cuba::Rendering
88
- Cuba.set :template_engine, "haml"
97
+ Cuba.plugin Cuba::Render
98
+ Cuba.settings[:render][:template_engine] = "haml"
89
99
 
90
100
  Cuba.define do
91
101
  on "home" do
@@ -103,9 +113,11 @@ end
103
113
  Authoring your own plugins is pretty straightforward.
104
114
 
105
115
  ``` ruby
116
+ require "bluecloth"
117
+
106
118
  module MyOwnHelper
107
119
  def markdown(str)
108
- BlueCloth.new(str).to_html
120
+ Markdown.new(str).to_html
109
121
  end
110
122
  end
111
123
 
@@ -120,22 +132,22 @@ A more complicated plugin for example, will make use of
120
132
  `Cuba.settings` to provide default values:
121
133
 
122
134
  ``` ruby
123
- module Rendering
135
+ module MarkdownView
124
136
  def self.setup(app)
125
- app.settings[:template_engine] = "erb"
137
+ app.settings[:markdown_view] ||= {}
138
+ app.settings[:markdown_view][:views] = "markdown"
126
139
  end
127
140
 
128
- def partial(template, locals = {})
129
- render("#{template}.#{settings[:template_engine]}", locals)
141
+ def markdown_view(template)
142
+ data = File.read("#{settings[:markdown_view][:views]}/#{template}.markdown")
143
+
144
+ res.write Markdown.new(data).to_html
130
145
  end
131
146
  end
132
147
 
133
- Cuba.plugin Rendering
148
+ Cuba.plugin MarkdownView
134
149
  ```
135
150
 
136
- This sample plugin actually resembles how `Cuba::Rendering` works.
137
-
138
151
  [cuba]: http://cuba.is
139
- [sites]: http://cuba.is/sites
140
152
  [mote]: http://github.com/soveran/mote
141
153
  [unix]: http://en.wikipedia.org/wiki/Unix_philosophy
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cuba-contrib"
3
- s.version = "3.1.0.rc2"
3
+ s.version = "3.1.0"
4
4
  s.summary = "Cuba plugins and utilities."
5
5
  s.description = "Includes various helper tools for Cuba."
6
6
  s.authors = ["Cyril David"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  "test/*.*"
17
17
  ]
18
18
 
19
- s.add_dependency "cuba", "3.1.0.rc2"
19
+ s.add_dependency "cuba", "~> 3.1"
20
20
  s.add_development_dependency "cutest"
21
- s.add_development_dependency "capybara"
21
+ s.add_development_dependency "mote", "~> 1.0"
22
22
  end
@@ -11,7 +11,7 @@ class Cuba
11
11
  end
12
12
 
13
13
  def partial(template, locals = {})
14
- mote(mote_path(template), locals.merge(this: self))
14
+ mote(mote_path(template), locals.merge(this: self), TOPLEVEL_BINDING)
15
15
  end
16
16
 
17
17
  def view(template, locals = {}, layout = settings[:mote][:layout])
@@ -36,6 +36,20 @@ Cuba.define do
36
36
  on "abs_path" do
37
37
  res.write view("./test/views/custom/abs_path.mote", title: "Absolute")
38
38
  end
39
+
40
+ def foo
41
+ req.path
42
+ end
43
+
44
+ on "foo" do
45
+ on "right" do
46
+ res.write partial("foo-right")
47
+ end
48
+
49
+ on "wrong" do
50
+ res.write partial("foo-wrong")
51
+ end
52
+ end
39
53
  end
40
54
 
41
55
  test "view" do
@@ -79,3 +93,13 @@ test "use of absolute mote path for the layout" do
79
93
 
80
94
  assert_response body, ["<title>Custom Layout: Hola</title>\n<h1>Home</h1>\n\n"]
81
95
  end
96
+
97
+ test "attempting to use defined variables in cuba context is a problem" do
98
+ assert_raise NameError do
99
+ Cuba.call({ "PATH_INFO" => "/foo/wrong", "SCRIPT_NAME" => "" })
100
+ end
101
+
102
+ _, _, body = Cuba.call({ "PATH_INFO" => "/foo/right", "SCRIPT_NAME" => "" })
103
+
104
+ assert_response body, ["/foo/right\n"]
105
+ end
metadata CHANGED
@@ -1,32 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuba-contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.rc2
5
- prerelease: 6
4
+ version: 3.1.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Cyril David
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cuba
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.0.rc2
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.1.0.rc2
29
+ version: '3.1'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: cutest
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -44,21 +44,21 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: capybara
47
+ name: mote
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '1.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.0'
62
62
  description: Includes various helper tools for Cuba.
63
63
  email:
64
64
  - me@cyrildavid.com
@@ -94,9 +94,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
- - - ! '>'
97
+ - - ! '>='
98
98
  - !ruby/object:Gem::Version
99
- version: 1.3.1
99
+ version: '0'
100
100
  requirements: []
101
101
  rubyforge_project:
102
102
  rubygems_version: 1.8.23