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.
Files changed (58) hide show
  1. data/Gemfile +11 -8
  2. data/README.md +50 -1
  3. data/Rakefile +14 -104
  4. data/config.ru +5 -0
  5. data/examples/blog/config.ru +1 -0
  6. data/lib/renee.rb +3 -2
  7. data/lib/renee/render.rb +1 -1
  8. data/lib/renee/url_generation.rb +66 -45
  9. data/lib/renee/version.rb +1 -1
  10. data/plan.txt +1 -5
  11. data/renee.gemspec +3 -3
  12. data/site/public/css/app.css +47 -26
  13. data/site/views/extending.md +66 -0
  14. data/site/views/index.md +14 -4
  15. data/site/views/routing.md +0 -38
  16. data/site/views/variable-types.md +2 -2
  17. data/test/{renee/blog_test.rb → blog_test.rb} +0 -0
  18. data/test/{renee-render/render_test.rb → render_test.rb} +0 -0
  19. data/test/renee-url-generation/test_helper.rb +1 -1
  20. data/test/{renee-session/session_test.rb → session_test.rb} +2 -2
  21. data/test/renee/test_helper.rb b/data/test/test_helper → copy.rb +0 -0
  22. data/test/test_helper.rb +8 -1
  23. data/test/{renee-url-generation/url_generation_test.rb → url_generation_test.rb} +2 -2
  24. metadata +47 -77
  25. data/Gemfile-renee +0 -8
  26. data/Gemfile-renee-core +0 -8
  27. data/Gemfile-renee-render +0 -9
  28. data/Gemfile-renee-session +0 -9
  29. data/Gemfile-renee-url-generation +0 -8
  30. data/README-renee-core.md +0 -242
  31. data/README-renee-render.md +0 -38
  32. data/README-renee-session.md +0 -3
  33. data/README-renee-url-generation.md +0 -3
  34. data/lib/renee/core.rb +0 -98
  35. data/lib/renee/core/chaining.rb +0 -66
  36. data/lib/renee/core/env_accessors.rb +0 -72
  37. data/lib/renee/core/exceptions.rb +0 -15
  38. data/lib/renee/core/matcher.rb +0 -61
  39. data/lib/renee/core/plugins.rb +0 -31
  40. data/lib/renee/core/rack_interaction.rb +0 -50
  41. data/lib/renee/core/request_context.rb +0 -56
  42. data/lib/renee/core/responding.rb +0 -112
  43. data/lib/renee/core/response.rb +0 -78
  44. data/lib/renee/core/routing.rb +0 -319
  45. data/lib/renee/core/transform.rb +0 -18
  46. data/renee-core.gemspec +0 -26
  47. data/renee-render.gemspec +0 -30
  48. data/renee-session.gemspec +0 -28
  49. data/renee-url-generation.gemspec +0 -24
  50. data/test.watchr +0 -61
  51. data/test/renee-core/chaining_test.rb +0 -33
  52. data/test/renee-core/env_accessors_test.rb +0 -43
  53. data/test/renee-core/include_test.rb +0 -14
  54. data/test/renee-core/request_context_test.rb +0 -70
  55. data/test/renee-core/responding_test.rb +0 -128
  56. data/test/renee-core/routing_test.rb +0 -443
  57. data/test/renee-core/test_helper.rb +0 -4
  58. 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 :name => 'renee'
4
- gemspec :name => 'renee-core'
5
- gemspec :name => 'renee-render'
3
+ gemspec
6
4
 
7
- gem 'rdiscount'
8
- gem 'haml'
9
- gem 'rack-codehighlighter'
10
- gem 'rack-google-analytics'
11
- gem 'coderay'
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
- def lsh(cmd, &block)
8
- out, code = lsh_with_code(cmd, &block)
9
- code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
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
- def lsh_with_code(cmd, &block)
13
- cmd << " 2>&1"
14
- outbuf = ''
15
- outbuf = `#{cmd}`
16
- if $? == 0
17
- block.call(outbuf) if block
18
- end
19
- [outbuf, $?]
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
@@ -1,3 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup
5
+
1
6
  require 'renee'
2
7
  require 'haml'
3
8
  require 'rdiscount'
@@ -40,6 +40,7 @@ run Renee {
40
40
  end
41
41
  end
42
42
  }.setup {
43
+ use Rack::Lint
43
44
  use Rack::MethodOverride
44
45
  views_path File.expand_path(File.dirname(__FILE__) + "/views")
45
46
  }
@@ -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.app(&blk)
16
+ app_class.run(&blk)
16
17
  app_class
17
18
  end
18
19
 
@@ -52,7 +52,7 @@ module Renee
52
52
  ##
53
53
  # Exception responsible for when an expected template does not exist.
54
54
  #
55
- class TemplateNotFound < RuntimeError; end
55
+ TemplateNotFound = Class.new(RuntimeError)
56
56
 
57
57
  # Same as render but automatically halts.
58
58
  # @param (see #render)
@@ -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
- generator = self
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
- def defaults_for_generation(defaults)
81
- @generation_defaults && defaults ? @generation_defaults.merge(defaults) : (defaults || @generation_defaults)
82
- end
106
+ # @private
107
+ class Generator
108
+ attr_reader :defaults
83
109
 
84
- # @private
85
- class Generator
86
- attr_reader :defaults
87
-
88
- def initialize(template, defaults = nil)
89
- @defaults = defaults
90
- parsed_template = URI.parse(template)
91
- @host = parsed_template.host
92
- @template = parsed_template.path
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
- def path(*args)
101
- opts = args.last.is_a?(Hash) ? args.pop : nil
102
- opts = opts ? defaults.merge(opts) : defaults.dup if defaults
103
- path = @template.gsub(/:([a-zA-Z0-9_]+)/) { |name|
104
- name = name[1, name.size - 1].to_sym
105
- (opts && opts.delete(name)) || (defaults && defaults[name]) || args.shift || raise("variable #{name.inspect} not found")
106
- }
107
- URI.encode(opts.nil? || opts.empty? ? path : "#{path}?#{Rack::Utils.build_query(opts)}")
108
- end
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
- def url(*args)
111
- raise "This URL cannot be generated as no host has been defined." if @host.nil?
112
- "#{@scheme}://#{@host}#{@port_part}#{path(*args)}"
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
@@ -1,4 +1,4 @@
1
1
  module Renee
2
2
  # The current version of Renee
3
- VERSION = "0.4.0.pre1"
3
+ VERSION = "0.4.0.pre2"
4
4
  end
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
- - fenerators (a la padrino)
10
+ - generators (a la padrino)
15
11
 
16
12
  things to do to explain it better
17
13
 
@@ -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', "~> 1.3.0"
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.6.1"
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"