renee 0.4.0.pre1 → 0.4.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -8
- data/README.md +50 -1
- data/Rakefile +14 -104
- data/config.ru +5 -0
- data/examples/blog/config.ru +1 -0
- data/lib/renee.rb +3 -2
- data/lib/renee/render.rb +1 -1
- data/lib/renee/url_generation.rb +66 -45
- data/lib/renee/version.rb +1 -1
- data/plan.txt +1 -5
- data/renee.gemspec +3 -3
- data/site/public/css/app.css +47 -26
- data/site/views/extending.md +66 -0
- data/site/views/index.md +14 -4
- data/site/views/routing.md +0 -38
- data/site/views/variable-types.md +2 -2
- data/test/{renee/blog_test.rb → blog_test.rb} +0 -0
- data/test/{renee-render/render_test.rb → render_test.rb} +0 -0
- data/test/renee-url-generation/test_helper.rb +1 -1
- data/test/{renee-session/session_test.rb → session_test.rb} +2 -2
- data/test/renee/test_helper.rb b/data/test/test_helper → copy.rb +0 -0
- data/test/test_helper.rb +8 -1
- data/test/{renee-url-generation/url_generation_test.rb → url_generation_test.rb} +2 -2
- metadata +47 -77
- data/Gemfile-renee +0 -8
- data/Gemfile-renee-core +0 -8
- data/Gemfile-renee-render +0 -9
- data/Gemfile-renee-session +0 -9
- data/Gemfile-renee-url-generation +0 -8
- data/README-renee-core.md +0 -242
- data/README-renee-render.md +0 -38
- data/README-renee-session.md +0 -3
- data/README-renee-url-generation.md +0 -3
- data/lib/renee/core.rb +0 -98
- data/lib/renee/core/chaining.rb +0 -66
- data/lib/renee/core/env_accessors.rb +0 -72
- data/lib/renee/core/exceptions.rb +0 -15
- data/lib/renee/core/matcher.rb +0 -61
- data/lib/renee/core/plugins.rb +0 -31
- data/lib/renee/core/rack_interaction.rb +0 -50
- data/lib/renee/core/request_context.rb +0 -56
- data/lib/renee/core/responding.rb +0 -112
- data/lib/renee/core/response.rb +0 -78
- data/lib/renee/core/routing.rb +0 -319
- data/lib/renee/core/transform.rb +0 -18
- data/renee-core.gemspec +0 -26
- data/renee-render.gemspec +0 -30
- data/renee-session.gemspec +0 -28
- data/renee-url-generation.gemspec +0 -24
- data/test.watchr +0 -61
- data/test/renee-core/chaining_test.rb +0 -33
- data/test/renee-core/env_accessors_test.rb +0 -43
- data/test/renee-core/include_test.rb +0 -14
- data/test/renee-core/request_context_test.rb +0 -70
- data/test/renee-core/responding_test.rb +0 -128
- data/test/renee-core/routing_test.rb +0 -443
- data/test/renee-core/test_helper.rb +0 -4
- data/test/renee-core/variable_type_test.rb +0 -57
data/Gemfile
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
gemspec
|
4
|
-
gemspec :name => 'renee-core'
|
5
|
-
gemspec :name => 'renee-render'
|
3
|
+
gemspec
|
6
4
|
|
7
|
-
|
8
|
-
gem '
|
9
|
-
gem '
|
10
|
-
gem 'rack-
|
11
|
-
gem '
|
5
|
+
group :site do
|
6
|
+
gem 'rdiscount'
|
7
|
+
gem 'haml'
|
8
|
+
gem 'rack-codehighlighter'
|
9
|
+
gem 'rack-google-analytics'
|
10
|
+
gem 'coderay'
|
11
|
+
end
|
12
12
|
|
13
13
|
group :development do
|
14
|
+
gem 'minitest', '~> 2.11.1'
|
15
|
+
gem 'rack-test', '>= 0.5.0'
|
14
16
|
gem 'shotgun'
|
15
17
|
gem 'rake'
|
18
|
+
gem 'json'
|
16
19
|
gem 'yard', '~> 0.7.4'
|
17
20
|
end
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Renee
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/renee-project/renee.png)](http://travis-ci.org/renee-project/renee)
|
4
|
+
|
3
5
|
The super friendly rack-based web framework.
|
4
6
|
|
5
7
|
## Introduction
|
@@ -132,4 +134,51 @@ run Renee.core {
|
|
132
134
|
```
|
133
135
|
|
134
136
|
This implements the standard 7 REST actions in a very concise and simple way. The routes and the actions blended together utilizing the various
|
135
|
-
Renee routing methods and block syntax. The routing methods are defined below, followed by an explanation of how to respond to a route.
|
137
|
+
Renee routing methods and block syntax. The routing methods are defined below, followed by an explanation of how to respond to a route.
|
138
|
+
|
139
|
+
# Renee Render
|
140
|
+
|
141
|
+
Rendering templates in Renee should be familiar and intuitive using the `render` command:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
run Renee.core {
|
145
|
+
path('blog') do
|
146
|
+
get { render! "blogs/index", :haml }
|
147
|
+
end
|
148
|
+
}
|
149
|
+
```
|
150
|
+
|
151
|
+
This above is the standard render syntax, specifying the engine followed by the template. You can also render without specifying an engine:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
path('blog') do
|
155
|
+
get { render! "blogs/index" }
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
This will do a lookup in the views path to find the appropriately named template. You can also pass locals and layout options as you would expect:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
path('blog') do
|
163
|
+
get { render! "blogs/index", :locals => { :foo => "bar" }, :layout => :bar }
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
This will render the "blogs/index.erb" file if it exists, passing the 'foo' local variable
|
168
|
+
and wrapping the result in the 'bar.erb' layout file. You can also render without returning the response by using:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
path('blog') do
|
172
|
+
get { render "blogs/index" }
|
173
|
+
end
|
174
|
+
```
|
175
|
+
|
176
|
+
This allows you to render the content as a string without immediately responding.
|
177
|
+
|
178
|
+
# Renee Session
|
179
|
+
|
180
|
+
Defines methods for accessing the session.
|
181
|
+
|
182
|
+
# Renee URL Generation
|
183
|
+
|
184
|
+
The URL generation is pretty nifty.
|
data/Rakefile
CHANGED
@@ -1,113 +1,23 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'yard'
|
2
4
|
|
3
5
|
ROOT = File.expand_path(File.dirname(__FILE__))
|
4
6
|
|
5
7
|
task :default => :test
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
Rake::TestTask.new do |t|
|
10
|
+
t.libs.push "lib"
|
11
|
+
t.test_files = FileList[File.expand_path("../test/**/*_test.rb", __FILE__)]
|
12
|
+
t.verbose = true
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
renee_gems = %w[
|
23
|
-
renee-core
|
24
|
-
renee-render
|
25
|
-
renee-url-generation
|
26
|
-
renee-session
|
27
|
-
renee
|
28
|
-
].freeze
|
29
|
-
|
30
|
-
desc "build #{renee_gems.join(', ')} gems"
|
31
|
-
task :build do
|
32
|
-
renee_gems.each do |g|
|
33
|
-
lsh "mkdir -p pkg && gem build #{g}.gemspec && mv *.gem pkg"
|
34
|
-
puts "#{g} built"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
task :release => [:build, :yard] do
|
39
|
-
require File.join(ROOT, 'lib', 'renee', 'version')
|
40
|
-
version_tag = "v#{Renee::VERSION}"
|
41
|
-
begin
|
42
|
-
raise("#{version_tag} has already been committed") if lsh('git tag').split(/\n/).include?(version_tag)
|
43
|
-
sh "git tag #{version_tag}"
|
44
|
-
puts "adding tag #{version_tag}"
|
45
|
-
renee_gems.each do |g|
|
46
|
-
sh "gem push pkg/#{g}-#{Renee::VERSION}.gem"
|
47
|
-
puts "#{g} pushed"
|
48
|
-
end
|
49
|
-
sh "git push"
|
50
|
-
sh "git push --tags"
|
51
|
-
rescue
|
52
|
-
puts "something went wrong"
|
53
|
-
sh "git tag -d #{version_tag}"
|
54
|
-
raise
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
task :install => :build do
|
59
|
-
require File.join(ROOT, 'lib', 'renee', 'version')
|
60
|
-
renee_gems.each do |g|
|
61
|
-
lsh "gem install pkg/#{g}-#{Renee::VERSION}.gem"
|
62
|
-
puts "#{g} installed"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
task :bundle do
|
67
|
-
renee_gems.each do |g|
|
68
|
-
sh "env BUNDLE_GEMFILE=Gemfile-#{g} bundle"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
renee_gems_tasks = Hash[renee_gems.map{|rg| [rg, :"test_#{rg.gsub('-', '_')}"]}].freeze
|
73
|
-
|
74
|
-
desc "Run tests for all renee stack gems"
|
75
|
-
task :test do
|
76
|
-
renee_gems_tasks.values.each do |task|
|
77
|
-
Rake::Task[task].invoke
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
renee_gems_tasks.each do |g, tn|
|
82
|
-
desc "Run tests for #{g} (shell out)"
|
83
|
-
task tn do
|
84
|
-
sh "env BUNDLE_GEMFILE=Gemfile-#{g} bundle exec rake test-#{g}"
|
85
|
-
end
|
86
|
-
|
87
|
-
Rake::TestTask.new("test-#{g}") do |t|
|
88
|
-
t.libs.push "lib"
|
89
|
-
t.test_files = FileList[File.expand_path("../test/#{g}/**/*_test.rb", __FILE__)]
|
90
|
-
t.verbose = true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
desc "Generate YARD documentation"
|
95
|
-
task :'yard' do
|
96
|
-
require 'yard'
|
97
|
-
Dir['*.gemspec'].to_a.each do |gemspec|
|
98
|
-
spec = Gem::Specification.load(gemspec)
|
99
|
-
puts "spec #{spec.inspect}"
|
100
|
-
task_name = :"yard:#{spec.name}"
|
101
|
-
rb_files = spec.files.select{|f| f[/^lib/]}
|
102
|
-
readme = spec.name == 'renee' ? "README.md" : "README-#{spec.name}.md"
|
103
|
-
pid = fork do # yard has some shared state somewhere. poor poor yard.
|
104
|
-
YARD::Rake::YardocTask.new(task_name) do |t|
|
105
|
-
t.options = ['-o', File.expand_path("../site/public/docs/#{spec.name}", __FILE__), '--readme', readme, '--no-private', '--markup', 'markdown']
|
106
|
-
t.files = rb_files
|
107
|
-
end
|
108
|
-
Rake::Task[task_name].execute
|
109
|
-
end
|
110
|
-
_, status = Process.waitpid2(pid)
|
111
|
-
raise unless status.success?
|
112
|
-
end
|
15
|
+
YARD::Rake::YardocTask.new do |t|
|
16
|
+
t.options = [
|
17
|
+
'-o', File.expand_path("../site/public/docs/core", __FILE__),
|
18
|
+
'--readme', 'README.md',
|
19
|
+
'--no-private',
|
20
|
+
'--markup', 'markdown'
|
21
|
+
]
|
22
|
+
t.files = 'lib/**/*.rb'
|
113
23
|
end
|
data/config.ru
CHANGED
data/examples/blog/config.ru
CHANGED
data/lib/renee.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'renee/version'
|
2
1
|
require 'renee/core'
|
2
|
+
|
3
|
+
require 'renee/version'
|
3
4
|
require 'renee/render'
|
4
5
|
require 'renee/session'
|
5
6
|
require 'renee/url_generation'
|
@@ -12,7 +13,7 @@ require 'renee/url_generation'
|
|
12
13
|
# }
|
13
14
|
def Renee(&blk)
|
14
15
|
app_class = Class.new(Renee::Application)
|
15
|
-
app_class.
|
16
|
+
app_class.run(&blk)
|
16
17
|
app_class
|
17
18
|
end
|
18
19
|
|
data/lib/renee/render.rb
CHANGED
@@ -52,7 +52,7 @@ module Renee
|
|
52
52
|
##
|
53
53
|
# Exception responsible for when an expected template does not exist.
|
54
54
|
#
|
55
|
-
|
55
|
+
TemplateNotFound = Class.new(RuntimeError)
|
56
56
|
|
57
57
|
# Same as render but automatically halts.
|
58
58
|
# @param (see #render)
|
data/lib/renee/url_generation.rb
CHANGED
@@ -8,12 +8,48 @@ module Renee
|
|
8
8
|
# Current version of Renee::URLGeneration
|
9
9
|
VERSION = Renee::VERSION
|
10
10
|
|
11
|
+
# @api private
|
11
12
|
def self.included(o)
|
12
13
|
o.extend(ClassMethods)
|
13
14
|
end
|
14
15
|
|
16
|
+
# Generates a url
|
17
|
+
# @see ClassMethods#url
|
18
|
+
def make_url(name, *args)
|
19
|
+
self.class.url(name, *args)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Generates a path
|
23
|
+
# @see ClassMethods#path
|
24
|
+
def make_path(name, *args)
|
25
|
+
self.class.path(name, *args)
|
26
|
+
end
|
27
|
+
|
15
28
|
# Class-methods included by this module.
|
16
29
|
module ClassMethods
|
30
|
+
def define_url_generation(&blk)
|
31
|
+
url_generator.instance_eval(&blk)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def url_generator
|
36
|
+
@generator ||= GeneratorSet.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class GeneratorSet
|
41
|
+
attr_accessor :generation_prefix
|
42
|
+
|
43
|
+
def initialize(prefix = '', defaults = nil, generators = {})
|
44
|
+
@url_generators = generators
|
45
|
+
@generation_prefix = prefix
|
46
|
+
@generation_defaults = defaults
|
47
|
+
end
|
48
|
+
|
49
|
+
def defaults_for_generation(defaults)
|
50
|
+
@generation_defaults && defaults ? @generation_defaults.merge(defaults) : (defaults || @generation_defaults)
|
51
|
+
end
|
52
|
+
|
17
53
|
# Registers new paths for generation.
|
18
54
|
# @param [Symbol] name The name of the path
|
19
55
|
# @param [String] pattern The pattern used for generation.
|
@@ -24,7 +60,7 @@ module Renee
|
|
24
60
|
# renee.path(:path, 123) # => "/my/123/path"
|
25
61
|
# renee.path(:path, :var => 'hey you') # => "/my/hey%20you/path"
|
26
62
|
def register(name, pattern, defaults = nil)
|
27
|
-
url_generators[name] = Generator.new("#{@generation_prefix}#{pattern}", defaults_for_generation(defaults))
|
63
|
+
@url_generators[name] = Generator.new("#{@generation_prefix}#{pattern}", defaults_for_generation(defaults))
|
28
64
|
end
|
29
65
|
|
30
66
|
# Allows the creation of generation contexts.
|
@@ -37,13 +73,7 @@ module Renee
|
|
37
73
|
# renee.register(:prefix_path, "/path") # would register /prefix/path
|
38
74
|
# }
|
39
75
|
def prefix(prefix, defaults = nil, &blk)
|
40
|
-
|
41
|
-
subgenerator = Class.new {
|
42
|
-
include URLGeneration::ClassMethods
|
43
|
-
define_method(:url_generators) { generator.send(:url_generators) }
|
44
|
-
}.new
|
45
|
-
subgenerator.instance_variable_set(:@generation_prefix, "#{@generation_prefix}#{prefix}")
|
46
|
-
subgenerator.instance_variable_set(:@generation_defaults, defaults_for_generation(defaults))
|
76
|
+
subgenerator = GeneratorSet.new("#{@generation_prefix}#{prefix}", defaults_for_generation(defaults), @url_generators)
|
47
77
|
if block_given?
|
48
78
|
old_prefix, old_defaults = @generation_prefix, @generation_defaults
|
49
79
|
@generation_prefix, @generation_defaults = "#{@generation_prefix}#{prefix}", defaults_for_generation(defaults)
|
@@ -60,7 +90,7 @@ module Renee
|
|
60
90
|
#
|
61
91
|
# @see #register
|
62
92
|
def path(name, *args)
|
63
|
-
generator = url_generators[name]
|
93
|
+
generator = @url_generators[name]
|
64
94
|
generator ? generator.path(*args) : raise("Generator for #{name} doesn't exist")
|
65
95
|
end
|
66
96
|
|
@@ -68,49 +98,40 @@ module Renee
|
|
68
98
|
# @param (see #path)
|
69
99
|
# @see #path
|
70
100
|
def url(name, *args)
|
71
|
-
generator = url_generators[name]
|
101
|
+
generator = @url_generators[name]
|
72
102
|
generator ? generator.url(*args) : raise("Generator for #{name} doesn't exist")
|
73
103
|
end
|
74
|
-
|
75
|
-
private
|
76
|
-
def url_generators
|
77
|
-
@url_generators ||= {}
|
78
|
-
end
|
104
|
+
end
|
79
105
|
|
80
|
-
|
81
|
-
|
82
|
-
|
106
|
+
# @private
|
107
|
+
class Generator
|
108
|
+
attr_reader :defaults
|
83
109
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
@
|
93
|
-
@scheme = parsed_template.scheme
|
94
|
-
port = parsed_template.port
|
95
|
-
if !port.nil? and (@scheme.nil? or @scheme == "http" && port != '80' or @scheme == "https" && port != '443')
|
96
|
-
@port_part = ":#{port}"
|
97
|
-
end
|
110
|
+
def initialize(template, defaults = nil)
|
111
|
+
@defaults = defaults
|
112
|
+
parsed_template = URI.parse(template)
|
113
|
+
@host = parsed_template.host
|
114
|
+
@template = parsed_template.path
|
115
|
+
@scheme = parsed_template.scheme
|
116
|
+
port = parsed_template.port
|
117
|
+
if !port.nil? and (@scheme.nil? or @scheme == "http" && port != '80' or @scheme == "https" && port != '443')
|
118
|
+
@port_part = ":#{port}"
|
98
119
|
end
|
120
|
+
end
|
99
121
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
122
|
+
def path(*args)
|
123
|
+
opts = args.last.is_a?(Hash) ? args.pop : nil
|
124
|
+
opts = opts ? defaults.merge(opts) : defaults.dup if defaults
|
125
|
+
path = @template.gsub(/:([a-zA-Z0-9_]+)/) { |name|
|
126
|
+
name = name[1, name.size - 1].to_sym
|
127
|
+
(opts && opts.delete(name)) || (defaults && defaults[name]) || args.shift || raise("variable #{name.inspect} not found")
|
128
|
+
}
|
129
|
+
URI.encode(opts.nil? || opts.empty? ? path : "#{path}?#{Rack::Utils.build_query(opts)}")
|
130
|
+
end
|
109
131
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
132
|
+
def url(*args)
|
133
|
+
raise "This URL cannot be generated as no host has been defined." if @host.nil?
|
134
|
+
"#{@scheme}://#{@host}#{@port_part}#{path(*args)}"
|
114
135
|
end
|
115
136
|
end
|
116
137
|
end
|
data/lib/renee/version.rb
CHANGED
data/plan.txt
CHANGED
@@ -5,13 +5,9 @@ things to do to make renee more complete
|
|
5
5
|
- authentication
|
6
6
|
- admin
|
7
7
|
|
8
|
-
things to do to make renee faster
|
9
|
-
|
10
|
-
- shorten the callstack in routing, it can get long
|
11
|
-
|
12
8
|
things to do to make renee easier to deal with
|
13
9
|
|
14
|
-
-
|
10
|
+
- generators (a la padrino)
|
15
11
|
|
16
12
|
things to do to explain it better
|
17
13
|
|
data/renee.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
$:.push File.expand_path("../../renee-core/lib", __FILE__)
|
4
3
|
require "renee/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
@@ -19,11 +18,12 @@ Gem::Specification.new do |s|
|
|
19
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
19
|
s.require_paths = ["lib"]
|
21
20
|
|
22
|
-
s.add_runtime_dependency 'rack', "
|
21
|
+
s.add_runtime_dependency 'rack', ">= 1.3.0"
|
23
22
|
s.add_runtime_dependency 'tilt', "~> 1.3.3"
|
24
23
|
s.add_runtime_dependency 'callsite', '~> 0.0.6'
|
24
|
+
s.add_runtime_dependency 'renee-core', '0.4.0.pre2'
|
25
25
|
|
26
|
-
s.add_development_dependency 'minitest', "~> 2.
|
26
|
+
s.add_development_dependency 'minitest', "~> 2.11.1"
|
27
27
|
s.add_development_dependency 'rake'
|
28
28
|
s.add_development_dependency 'bundler'
|
29
29
|
s.add_development_dependency "rack-test", ">= 0.5.0"
|