padrino-core 0.9.7 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'sdoc'
4
3
 
5
4
  begin
6
5
  require 'jeweler'
@@ -13,7 +12,7 @@ begin
13
12
  gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
14
13
  gem.executables = ["padrino"]
15
14
  gem.rubyforge_project = 'padrino-core'
16
- gem.add_runtime_dependency "sinatra", ">= 0.9.6"
15
+ gem.add_runtime_dependency "sinatra", ">= 1.0.0"
17
16
  gem.add_runtime_dependency "i18n", ">= 0.3.2"
18
17
  gem.add_runtime_dependency "usher", ">= 0.6.2"
19
18
  gem.add_runtime_dependency "thor", ">= 0.13.0"
@@ -23,6 +22,7 @@ begin
23
22
  gem.add_development_dependency "mocha", ">= 0.9.7"
24
23
  gem.add_development_dependency "rack-test", ">= 0.5.0"
25
24
  gem.add_development_dependency "webrat", ">= 0.5.1"
25
+ gem.add_development_dependency "haml", ">= 2.2.22"
26
26
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
27
27
  end
28
28
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.7
1
+ 0.9.9
@@ -6,4 +6,15 @@ $:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.inclu
6
6
 
7
7
  require 'padrino-core/cli/base'
8
8
 
9
+ if %w(g gen).include?(ARGV[0])
10
+ ARGV.shift
11
+ padrino_gen = File.join(padrino_core_path, "/../../padrino-gen/bin/padrino-gen")
12
+ if File.exist?(padrino_gen)
13
+ system "#{padrino_gen} #{ARGV.join(" ")}"
14
+ else
15
+ puts "<= You need padrino-gen! Run: gem install padrino-gen"
16
+ end
17
+ exit(0)
18
+ end
19
+
9
20
  Padrino::Cli::Base.start(ARGV)
@@ -1,4 +1,5 @@
1
1
  require 'sinatra/base'
2
+ require 'padrino-core/support_lite'
2
3
 
3
4
  Dir[File.dirname(__FILE__) + '/padrino-core/application/*.rb'].each {|file| require file }
4
5
  Dir[File.dirname(__FILE__) + '/padrino-core/*.rb'].each {|file| require file }
@@ -196,7 +196,7 @@ module Padrino
196
196
 
197
197
  private
198
198
  def clean_backtrace(trace)
199
- return trace unless options.clean_trace?
199
+ return trace unless settings.clean_trace?
200
200
  trace.reject { |line|
201
201
  line =~ /lib\/sinatra.*\.rb|lib\/padrino.*\.rb/ ||
202
202
  (defined?(Gem) && line.include?(Gem.dir))
@@ -1,9 +1,22 @@
1
1
  module Padrino
2
2
  ##
3
3
  # Padrino enhances the Sinatra ‘render’ method to have support for automatic template engine detection,
4
- # among other more advanced features.
4
+ # enhanced layout functionality, locale enabled rendering, among other features.
5
5
  #
6
6
  module Rendering
7
+ class TemplateNotFound < RuntimeError #:nodoc:
8
+ end
9
+
10
+ ##
11
+ # This is an array of file patterns to ignore.
12
+ # If your editor add a suffix during editing to your files please add it like:
13
+ #
14
+ # Padrino::Rendering::IGNORE_FILE_PATTERN << /~$/
15
+ #
16
+ IGNORE_FILE_PATTERN = [
17
+ /~$/ # This is for Gedit
18
+ ]
19
+
7
20
  def self.registered(app)
8
21
  app.send(:include, Padrino::Rendering)
9
22
  end
@@ -30,43 +43,60 @@ module Padrino
30
43
 
31
44
  private
32
45
  ##
33
- # Hijacking the sinatra render for:
46
+ # Enhancing Sinatra render functionality for:
34
47
  #
35
- # * Use layout like rails do
36
- # * Use render 'path/to/my/template' (without symbols)
37
- # * Use render 'path/to/my/template' (with auto enegine lookup)
48
+ # * Using layout similar to rails
49
+ # * Use render 'path/to/my/template' (without symbols)
50
+ # * Use render 'path/to/my/template' (with engine lookup)
51
+ # * Use render 'path/to/template.haml' (with explicit engine lookup)
38
52
  # * Use render 'path/to/template', :layout => false
39
53
  # * Use render 'path/to/template', :layout => false, :engine => 'haml'
40
54
  # * Use render { :a => 1, :b => 2, :c => 3 } # => return a json string
41
55
  #
42
56
  def render(engine, data=nil, options={}, locals={}, &block)
43
- clear_template_cache!
44
-
45
- # If engine is an hash we convert to json
57
+ # If engine is a hash then render data converted to json
46
58
  return engine.to_json if engine.is_a?(Hash)
47
59
 
48
- # Data can be a hash of options sometimes mistakenly
60
+ # Data can actually be a hash of options in certain cases
49
61
  options.merge!(data) && data = nil if data.is_a?(Hash)
50
62
 
51
- # If an engine is a string probably is a path so we try to resolve them
63
+ # If an engine is a string then this is a likely a path to be resolved
52
64
  data, engine = *resolve_template(engine, options) if data.nil?
53
65
 
54
- # We need for Sinatra 1.0 an outvar for erb and erubis templates
66
+ # Sinatra 1.0 requires an outvar for erb and erubis templates
55
67
  options[:outvar] ||= '@_out_buf' if [:erb, :erubis].include?(engine)
56
68
 
57
- # Use layout as rails do
69
+ # Resolve layouts similar to in Rails
58
70
  if (options[:layout].nil? || options[:layout] == true) && !self.class.templates.has_key?(:layout)
59
- if layout = self.class.instance_variable_defined?(:@_layout) ? self.class.instance_variable_get(:@_layout) : :application
60
- layout = Dir["#{self.options.views}/#{layout}.*"].any? ? layout.to_sym : File.join('layouts', layout.to_s).to_sym
61
- options[:layout] = resolve_template(layout)[0] rescue nil
62
- logger.debug "Rendering layout #{options[:layout]}" if defined?(logger) && options[:layout]
63
- end
71
+ options[:layout] = resolved_layout
72
+ logger.debug "Resolving layout #{options[:layout]}" if defined?(logger) && options[:layout]
64
73
  end
74
+
75
+ # Pass arguments to Sinatra render method
65
76
  super(engine, data, options, locals, &block)
66
77
  end
67
78
 
68
79
  ##
69
- # Returns the template path and engine that match (if presents) content_type, I18n.locale.
80
+ # Returns the located layout to be used for the rendered template (if available)
81
+ #
82
+ # ==== Example
83
+ #
84
+ # resolve_layout(true)
85
+ # => "/layouts/custom"
86
+ #
87
+ def resolved_layout
88
+ layout_var = self.class.instance_variable_get(:@_layout) || :application
89
+ has_layout_at_root = Dir["#{self.settings.views}/#{layout_var}.*"].any?
90
+ layout_path = has_layout_at_root ? layout_var.to_sym : File.join('layouts', layout_var.to_s).to_sym
91
+ resolve_template(layout_path, :strict_format => true)[0] rescue nil
92
+ end
93
+
94
+ ##
95
+ # Returns the template path and engine that match content_type (if present), I18n.locale.
96
+ #
97
+ # === Options
98
+ #
99
+ # :strict_format:: The resolved template must match the content_type of the request (defaults to false)
70
100
  #
71
101
  # ==== Example
72
102
  #
@@ -75,33 +105,28 @@ module Padrino
75
105
  # # If you request "/foo" with I18n.locale == :de => [:"/path/to/foo.de.haml", :haml]
76
106
  #
77
107
  def resolve_template(template_path, options={})
108
+ options.reverse_merge!(:strict_format => false)
78
109
  view_path = options.delete(:views) || self.options.views || self.class.views || "./views"
79
110
  template_path = "/#{template_path}" unless template_path.to_s =~ /^\//
111
+ target_extension = File.extname(template_path)[1..-1] || "none" # retrieves explicit template extension
112
+ template_path = template_path.chomp(".#{target_extension}")
113
+
80
114
  templates = Dir[File.join(view_path, template_path) + ".*"].map do |file|
81
- template_file = file.sub(view_path, '').chomp(File.extname(file)).to_sym # retrieves relative file path
82
- template_engine = options[:engine] || File.extname(file)[1..-1].to_sym # retrieves engine extension
83
- [template_file, template_engine]
115
+ template_engine = File.extname(file)[1..-1].to_sym # retrieves engine extension
116
+ template_file = file.sub(view_path, '').chomp(".#{template_engine}").to_sym # retrieves template filename
117
+ [template_file, template_engine] unless IGNORE_FILE_PATTERN.any? { |pattern| template_engine.to_s =~ pattern }
84
118
  end
85
119
 
86
120
  located_template =
87
121
  templates.find { |file, e| defined?(I18n) && file.to_s == "#{template_path}.#{I18n.locale}.#{content_type}" } ||
88
122
  templates.find { |file, e| defined?(I18n) && file.to_s == "#{template_path}.#{I18n.locale}" && content_type == :html } ||
123
+ templates.find { |file, e| File.extname(file.to_s) == ".#{target_extension}" or e.to_s == target_extension.to_s } ||
89
124
  templates.find { |file, e| file.to_s == "#{template_path}.#{content_type}" } ||
90
- templates.find { |file, e| file.to_s == "#{template_path}" && content_type == :html }
125
+ templates.find { |file, e| file.to_s == "#{template_path}" && content_type == :html } ||
126
+ templates.any? && !options[:strict_format] && templates.first # If not strict, fall back to the first located template
91
127
 
92
- raise "Template path '#{template_path}' could not be located and rendered!" unless located_template
128
+ raise TemplateNotFound.new("Template path '#{template_path}' could not be located!") unless located_template
93
129
  located_template
94
130
  end
95
-
96
- ##
97
- # Clears the template view cache when in development mode
98
- # clear_template_cache!
99
- #
100
- def clear_template_cache!
101
- # TODO: remove @template_cache.respond_to?(:clear) when sinatra 1.0 will be released
102
- can_clear_cache = @template_cache && @template_cache.respond_to?(:clear)
103
- is_in_development = (defined?(Padrino) && Padrino.respond_to?(:env) && Padrino.env != :production)
104
- @template_cache.clear if is_in_development && can_clear_cache
105
- end
106
131
  end # Rendering
107
132
  end # Padrino
@@ -25,17 +25,6 @@ module Padrino
25
25
  # Compatibility with usher
26
26
  #
27
27
  def route!(base=self.class, pass_block=nil)
28
- # TODO: remove this when sinatra 1.0 will be released
29
- if Sinatra::VERSION =~ /^0\.9/
30
- # enable nested params in Rack < 1.0; allow indifferent access
31
- can_parse_nested = Rack::Utils.respond_to?(:parse_nested_query)
32
- @params = can_parse_nested ? indifferent_params(@request.params) : nested_params(@request.params)
33
- # deliver static files
34
- static! if options.static? && (request.get? || request.head?)
35
- # perform before filters
36
- self.class.filters.each { |block| instance_eval(&block) }
37
- end # for sinatra = 0.9
38
-
39
28
  # Usher
40
29
  if self.class.router and match = self.class.router.recognize(@request, @request.path_info)
41
30
  @block_params = match.params.map { |p| p.last }
@@ -69,7 +58,7 @@ module Padrino
69
58
  # serving files from the public directory
70
59
  #
71
60
  def static_file?(path_info)
72
- return if (public_dir = options.public).nil?
61
+ return if (public_dir = settings.public).nil?
73
62
  public_dir = File.expand_path(public_dir)
74
63
 
75
64
  path = File.expand_path(public_dir + unescape(path_info))
@@ -96,9 +85,7 @@ module Padrino
96
85
  end
97
86
 
98
87
  ##
99
- # Method for deliver static files, Sinatra 0.10.x or 1.0.x have this method
100
- # but for now we use this (because we need a compatibility with 0.9.x) and also
101
- # because we just have +static_file?+ method.
88
+ # Method for deliver static files.
102
89
  #
103
90
  def static!
104
91
  if path = static_file?(request.path_info)
@@ -18,14 +18,14 @@ module Padrino
18
18
  method_option :daemonize, :type => :boolean, :aliases => "-d", :desc => "Run daemonized in the background"
19
19
  def start
20
20
  prepare :start
21
- require File.dirname(__FILE__) + "/adapter"
21
+ require File.expand_path(File.dirname(__FILE__) + "/adapter")
22
22
  require 'config/boot'
23
23
  Padrino::Cli::Adapter.start(options)
24
24
  end
25
25
 
26
26
  desc "stop", "Stops the Padrino application"
27
27
  def stop
28
- require File.dirname(__FILE__) + "/adapter"
28
+ require File.expand_path(File.dirname(__FILE__) + "/adapter")
29
29
  Padrino::Cli::Adapter.stop
30
30
  end
31
31
 
@@ -44,7 +44,7 @@ module Padrino
44
44
  ARGV.concat(args)
45
45
  puts "=> Executing Rake #{ARGV.join(' ')} ..."
46
46
  ENV['PADRINO_LOG_LEVEL'] ||= "test"
47
- require File.dirname(__FILE__) + '/rake'
47
+ require File.expand_path(File.dirname(__FILE__) + '/rake')
48
48
  silence(:stdout) { require 'config/boot' }
49
49
  PadrinoTasks.init
50
50
  end
@@ -52,13 +52,13 @@ module Padrino
52
52
  desc "console", "Boots up the Padrino application irb console"
53
53
  def console
54
54
  prepare :console
55
- require File.dirname(__FILE__) + "/../version"
55
+ require File.expand_path(File.dirname(__FILE__) + "/../version")
56
56
  ARGV.clear
57
57
  puts "=> Loading #{options.environment} console (Padrino v.#{Padrino.version})"
58
58
  require 'irb'
59
59
  require "irb/completion"
60
60
  require 'config/boot'
61
- require File.dirname(__FILE__) + '/console'
61
+ require File.expand_path(File.dirname(__FILE__) + '/console')
62
62
  IRB.start
63
63
  end
64
64
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../tasks'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../tasks')
2
2
  require 'rake'
3
3
  Rake.application.instance_variable_set(:@rakefile, __FILE__)
4
4
 
@@ -19,6 +19,7 @@
19
19
  # * Hash#to_params
20
20
  # * Hash#symbolize_keys, Hash.symbolize_keys!
21
21
  # * Hash#reverse_merge, Hash#reverse_merge!
22
+ # * Symbol#to_proc
22
23
  # * SupportLite::OrderedHash
23
24
  #
24
25
 
@@ -33,6 +34,7 @@ require 'active_support/core_ext/object'
33
34
  require 'active_support/core_ext/object/blank'
34
35
  require 'active_support/core_ext/array'
35
36
  require 'active_support/core_ext/module'
37
+ require 'active_support/core_ext/symbol'
36
38
  require 'active_support/ordered_hash'
37
39
 
38
40
  ##
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-core}
8
- s.version = "0.9.7"
8
+ s.version = "0.9.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-03-22}
12
+ s.date = %q{2010-03-29}
13
13
  s.default_executable = %q{padrino}
14
14
  s.description = %q{The Padrino core gem required for use of this framework}
15
15
  s.email = %q{padrinorb@gmail.com}
@@ -64,6 +64,7 @@ Gem::Specification.new do |s|
64
64
  "test/test_mounter.rb",
65
65
  "test/test_reloader_complex.rb",
66
66
  "test/test_reloader_simple.rb",
67
+ "test/test_rendering.rb",
67
68
  "test/test_routing.rb",
68
69
  "test/test_server.rb"
69
70
  ]
@@ -79,7 +80,7 @@ Gem::Specification.new do |s|
79
80
  s.specification_version = 3
80
81
 
81
82
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
82
- s.add_runtime_dependency(%q<sinatra>, [">= 0.9.6"])
83
+ s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
83
84
  s.add_runtime_dependency(%q<i18n>, [">= 0.3.2"])
84
85
  s.add_runtime_dependency(%q<usher>, [">= 0.6.2"])
85
86
  s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
@@ -89,8 +90,9 @@ Gem::Specification.new do |s|
89
90
  s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
90
91
  s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
91
92
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
93
+ s.add_development_dependency(%q<haml>, [">= 2.2.22"])
92
94
  else
93
- s.add_dependency(%q<sinatra>, [">= 0.9.6"])
95
+ s.add_dependency(%q<sinatra>, [">= 1.0.0"])
94
96
  s.add_dependency(%q<i18n>, [">= 0.3.2"])
95
97
  s.add_dependency(%q<usher>, [">= 0.6.2"])
96
98
  s.add_dependency(%q<thor>, [">= 0.13.0"])
@@ -100,9 +102,10 @@ Gem::Specification.new do |s|
100
102
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
101
103
  s.add_dependency(%q<rack-test>, [">= 0.5.0"])
102
104
  s.add_dependency(%q<webrat>, [">= 0.5.1"])
105
+ s.add_dependency(%q<haml>, [">= 2.2.22"])
103
106
  end
104
107
  else
105
- s.add_dependency(%q<sinatra>, [">= 0.9.6"])
108
+ s.add_dependency(%q<sinatra>, [">= 1.0.0"])
106
109
  s.add_dependency(%q<i18n>, [">= 0.3.2"])
107
110
  s.add_dependency(%q<usher>, [">= 0.6.2"])
108
111
  s.add_dependency(%q<thor>, [">= 0.13.0"])
@@ -112,6 +115,7 @@ Gem::Specification.new do |s|
112
115
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
113
116
  s.add_dependency(%q<rack-test>, [">= 0.5.0"])
114
117
  s.add_dependency(%q<webrat>, [">= 0.5.1"])
118
+ s.add_dependency(%q<haml>, [">= 2.2.22"])
115
119
  end
116
120
  end
117
121
 
@@ -63,4 +63,35 @@ class Test::Unit::TestCase
63
63
  end
64
64
 
65
65
  alias :response :last_response
66
+
67
+ def create_template(name, content, options={})
68
+ FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
69
+ FileUtils.mkdir_p(File.dirname(__FILE__) + "/views/layouts")
70
+ path = "/views/#{name}"
71
+ path += ".#{options.delete(:locale)}" if options[:locale].present?
72
+ path += ".#{options[:format]}" if options[:format].present?
73
+ path += ".erb" unless options[:format].to_s =~ /haml|rss|atom/
74
+ path += ".builder" if options[:format].to_s =~ /rss|atom/
75
+ file = File.dirname(__FILE__) + path
76
+ File.open(file, 'w') { |io| io.write content }
77
+ file
78
+ end
79
+ alias :create_view :create_template
80
+ alias :create_layout :create_template
81
+
82
+ def remove_views
83
+ FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
84
+ end
85
+
86
+ def with_template(name, content, options={})
87
+ # Build a temp layout
88
+ template = create_template(name, content, options)
89
+ yield
90
+ ensure
91
+ # Remove temp layout
92
+ File.unlink(template) rescue nil
93
+ remove_views
94
+ end
95
+ alias :with_view :with_template
96
+ alias :with_layout :with_template
66
97
  end
@@ -1,37 +1,6 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestApplication < Test::Unit::TestCase
4
-
5
- def create_template(name, content, options={})
6
- FileUtils.mkdir_p(File.dirname(__FILE__) + "/views")
7
- FileUtils.mkdir_p(File.dirname(__FILE__) + "/views/layouts")
8
- path = "/views/#{name}"
9
- path += ".#{options.delete(:locale)}" if options[:locale].present?
10
- path += ".#{options.delete(:format)}" if options[:format].present?
11
- path += ".erb"
12
- file = File.dirname(__FILE__) + path
13
- File.open(file, 'w') { |io| io.write content }
14
- file
15
- end
16
- alias :create_view :create_template
17
- alias :create_layout :create_template
18
-
19
- def remove_views
20
- FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
21
- end
22
-
23
- def with_template(name, content, options={})
24
- # Build a temp layout
25
- template = create_template(name, content, options)
26
- yield
27
- ensure
28
- # Remove temp layout
29
- File.unlink(template) rescue nil
30
- remove_views
31
- end
32
- alias :with_view :with_template
33
- alias :with_layout :with_template
34
-
35
4
  def teardown
36
5
  remove_views
37
6
  end
@@ -54,7 +23,6 @@ class TestApplication < Test::Unit::TestCase
54
23
  assert !PadrinoTestApp.instance_variable_get(:@_configured)
55
24
  PadrinoTestApp.send(:setup_application!)
56
25
  assert PadrinoTestApp.instance_variable_get(:@_configured)
57
- assert !PadrinoTestApp.send(:find_view_path)
58
26
  assert !PadrinoTestApp.reload?
59
27
  assert 'padrino_test_app', PadrinoTestApp.app_name
60
28
  assert 'StandardFormBuilder', PadrinoTestApp.default_builder
@@ -63,232 +31,4 @@ class TestApplication < Test::Unit::TestCase
63
31
  assert !PadrinoTestApp.padrino_helpers
64
32
  end
65
33
  end
66
-
67
- context 'for application layout functionality' do
68
-
69
- should 'get no layout' do
70
- mock_app do
71
- get("/"){ "no layout" }
72
- end
73
-
74
- get "/"
75
- assert_equal "no layout", body
76
- end
77
-
78
- should 'be compatible with sinatra layout' do
79
- mock_app do
80
- layout do
81
- "this is a <%= yield %>"
82
- end
83
-
84
- get("/"){ render :erb, "sinatra layout" }
85
- end
86
-
87
- get "/"
88
- assert_equal "this is a sinatra layout", body
89
- end
90
-
91
- should 'use rails way layout' do
92
- with_layout :application, "this is a <%= yield %>" do
93
- mock_app do
94
- get("/"){ render :erb, "rails way layout" }
95
- end
96
-
97
- get "/"
98
- assert_equal "this is a rails way layout", body
99
- end
100
- end
101
-
102
- should 'use rails way for a custom layout' do
103
- with_layout "layouts/custom", "this is a <%= yield %>" do
104
- mock_app do
105
- layout :custom
106
- get("/"){ render :erb, "rails way custom layout" }
107
- end
108
-
109
- get "/"
110
- assert_equal "this is a rails way custom layout", body
111
- end
112
- end
113
-
114
- should 'not use layout' do
115
- with_layout :application, "this is a <%= yield %>" do
116
- with_view :index, "index" do
117
- mock_app do
118
- get("/with/layout"){ render :index }
119
- get("/without/layout"){ render :index, :layout => false }
120
- end
121
- get "/with/layout"
122
- assert_equal "this is a index", body
123
- get "/without/layout"
124
- assert_equal "index", body
125
- end
126
- end
127
- end
128
- end
129
-
130
- context 'for application render functionality' do
131
-
132
- should 'be compatible with sinatra render' do
133
- mock_app do
134
- get("/"){ render :erb, "<%= 1+2 %>" }
135
- end
136
- get "/"
137
- assert_equal "3", body
138
- end
139
-
140
- should 'be compatible with sinatra views' do
141
- with_view :index, "<%= 1+2 %>" do
142
- mock_app do
143
- get("/foo") { render :erb, :index }
144
- get("/bar") { erb :index }
145
- get("/dir") { "3" }
146
- get("/inj") { erb "<%= 2+1 %>" }
147
- get("/rnj") { render :erb, "<%= 2+1 %>" }
148
- end
149
- get "/foo"
150
- assert_equal "3", body
151
- get "/bar"
152
- assert_equal "3", body
153
- get "/dir"
154
- assert_equal "3", body
155
- get "/inj"
156
- assert_equal "3", body
157
- get "/rnj"
158
- assert_equal "3", body
159
- end
160
- end
161
-
162
- should 'resolve template engine' do
163
- with_view :index, "<%= 1+2 %>" do
164
- mock_app do
165
- get("/foo") { render :index }
166
- get("/bar") { render "/index" }
167
- end
168
- get "/foo"
169
- assert_equal "3", body
170
- get "/bar"
171
- assert_equal "3", body
172
- end
173
- end
174
-
175
- should 'reslove template content type' do
176
- create_view :foo, "Im Js", :format => :js
177
- create_view :foo, "Im Erb"
178
- mock_app do
179
- get("/foo", :respond_to => :js) { render :foo }
180
- get("/bar.js") { render :foo }
181
- end
182
- get "/foo.js"
183
- assert_equal "Im Js", body
184
- get "/bar.js"
185
- assert_equal "Im Js", body
186
- remove_views
187
- end
188
-
189
- should 'reslove template locale' do
190
- create_view :foo, "Im English", :locale => :en
191
- create_view :foo, "Im Italian", :locale => :it
192
- mock_app do
193
- get("/foo") { render :foo }
194
- end
195
- I18n.locale = :en
196
- get "/foo"
197
- assert_equal "Im English", body
198
- I18n.locale = :it
199
- get "/foo"
200
- assert_equal "Im Italian", body
201
- end
202
-
203
- should 'resolve template content_type and locale' do
204
- create_view :foo, "Im Js", :format => :js
205
- create_view :foo, "Im Erb"
206
- create_view :foo, "Im English Erb", :locale => :en
207
- create_view :foo, "Im Italian Erb", :locale => :it
208
- create_view :foo, "Im English Js", :format => :js, :locale => :en
209
- create_view :foo, "Im Italian Js", :format => :js, :locale => :it
210
- mock_app do
211
- get("/foo", :respond_to => [:html, :js]) { render :foo }
212
- end
213
- I18n.locale = :none
214
- get "/foo.js"
215
- assert_equal "Im Js", body
216
- get "/foo"
217
- assert_equal "Im Erb", body
218
- I18n.locale = :en
219
- get "/foo"
220
- assert_equal "Im English Erb", body
221
- I18n.locale = :it
222
- get "/foo"
223
- assert_equal "Im Italian Erb", body
224
- I18n.locale = :en
225
- get "/foo.js"
226
- assert_equal "Im English Js", body
227
- I18n.locale = :it
228
- get "/foo.js"
229
- assert_equal "Im Italian Js", body
230
- I18n.locale = :en
231
- get "/foo.pk"
232
- assert_equal 404, status
233
- end
234
-
235
- should 'resolve template content_type and locale with layout' do
236
- create_layout :foo, "Hello <%= yield %> in a Js layout", :format => :js
237
- create_layout :foo, "Hello <%= yield %> in a Js-En layout", :format => :js, :locale => :en
238
- create_layout :foo, "Hello <%= yield %> in a Js-It layout", :format => :js, :locale => :it
239
- create_layout :foo, "Hello <%= yield %> in a Erb-En layout", :locale => :en
240
- create_layout :foo, "Hello <%= yield %> in a Erb-It layout", :locale => :it
241
- create_layout :foo, "Hello <%= yield %> in a Erb layout"
242
- create_view :bar, "Im Js", :format => :js
243
- create_view :bar, "Im Erb"
244
- create_view :bar, "Im English Erb", :locale => :en
245
- create_view :bar, "Im Italian Erb", :locale => :it
246
- create_view :bar, "Im English Js", :format => :js, :locale => :en
247
- create_view :bar, "Im Italian Js", :format => :js, :locale => :it
248
- create_view :bar, "Im a json", :format => :json
249
- mock_app do
250
- layout :foo
251
- get("/bar", :respond_to => [:html, :js, :json]) { render :bar }
252
- end
253
- I18n.locale = :none
254
- get "/bar.js"
255
- assert_equal "Hello Im Js in a Js layout", body
256
- get "/bar"
257
- assert_equal "Hello Im Erb in a Erb layout", body
258
- I18n.locale = :en
259
- get "/bar"
260
- assert_equal "Hello Im English Erb in a Erb-En layout", body
261
- I18n.locale = :it
262
- get "/bar"
263
- assert_equal "Hello Im Italian Erb in a Erb-It layout", body
264
- I18n.locale = :en
265
- get "/bar.js"
266
- assert_equal "Hello Im English Js in a Js-En layout", body
267
- I18n.locale = :it
268
- get "/bar.js"
269
- assert_equal "Hello Im Italian Js in a Js-It layout", body
270
- I18n.locale = :en
271
- get "/bar.json"
272
- assert_equal "Im a json", body
273
- get "/bar.pk"
274
- assert_equal 404, status
275
- end
276
-
277
- should 'renders erb with blocks' do
278
- mock_app do
279
- def container
280
- @_out_buf << "THIS."
281
- yield
282
- @_out_buf << "SPARTA!"
283
- end
284
- def is; "IS."; end
285
- get '/' do
286
- render :erb, '<% container do %> <%= is %> <% end %>'
287
- end
288
- end
289
- get '/'
290
- assert ok?
291
- assert_equal 'THIS. IS. SPARTA!', body
292
- end
293
- end
294
- end
34
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestCore < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestDependencies < Test::Unit::TestCase
4
4
  context 'when we require a dependency that have another dependecy' do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestPadrinoLogger < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestMounter < Test::Unit::TestCase
4
4
 
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/helper'
2
- require 'fixtures/apps/complex'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/complex')
3
3
 
4
4
  class TestComplexReloader < Test::Unit::TestCase
5
5
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require 'fixtures/apps/simple'
3
3
 
4
4
  class TestSimpleReloader < Test::Unit::TestCase
@@ -7,16 +7,16 @@ class TestSimpleReloader < Test::Unit::TestCase
7
7
 
8
8
  should 'reset routes' do
9
9
  mock_app do
10
- 1.step(10).each do |i|
10
+ (1..10).each do |i|
11
11
  get("/#{i}") { "Foo #{i}" }
12
12
  end
13
13
  end
14
- 1.step(10).each do |i|
14
+ (1..10).each do |i|
15
15
  get "/#{i}"
16
16
  assert_equal "Foo #{i}", body
17
17
  end
18
18
  @app.reset_routes!
19
- 1.step(10).each do |i|
19
+ (1..10).each do |i|
20
20
  get "/#{i}"
21
21
  assert_equal 404, status
22
22
  end
@@ -0,0 +1,297 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestRendering < Test::Unit::TestCase
4
+ def teardown
5
+ remove_views
6
+ end
7
+
8
+ context 'for application layout functionality' do
9
+
10
+ should 'get no layout' do
11
+ mock_app do
12
+ get("/"){ "no layout" }
13
+ end
14
+
15
+ get "/"
16
+ assert_equal "no layout", body
17
+ end
18
+
19
+ should 'be compatible with sinatra layout' do
20
+ mock_app do
21
+ layout do
22
+ "this is a <%= yield %>"
23
+ end
24
+
25
+ get("/"){ render :erb, "sinatra layout" }
26
+ end
27
+
28
+ get "/"
29
+ assert_equal "this is a sinatra layout", body
30
+ end
31
+
32
+ should 'use rails way layout' do
33
+ with_layout :application, "this is a <%= yield %>" do
34
+ mock_app do
35
+ get("/"){ render :erb, "rails way layout" }
36
+ end
37
+
38
+ get "/"
39
+ assert_equal "this is a rails way layout", body
40
+ end
41
+ end
42
+
43
+ should 'use rails way for a custom layout' do
44
+ with_layout "layouts/custom", "this is a <%= yield %>" do
45
+ mock_app do
46
+ layout :custom
47
+ get("/"){ render :erb, "rails way custom layout" }
48
+ end
49
+
50
+ get "/"
51
+ assert_equal "this is a rails way custom layout", body
52
+ end
53
+ end
54
+
55
+ should 'not use layout' do
56
+ with_layout :application, "this is a <%= yield %>" do
57
+ with_view :index, "index" do
58
+ mock_app do
59
+ get("/with/layout"){ render :index }
60
+ get("/without/layout"){ render :index, :layout => false }
61
+ end
62
+ get "/with/layout"
63
+ assert_equal "this is a index", body
64
+ get "/without/layout"
65
+ assert_equal "index", body
66
+ end
67
+ end
68
+ end
69
+
70
+ should 'not use layout with js format' do
71
+ create_layout :application, "this is an <%= yield %>"
72
+ create_view :foo, "erb file"
73
+ create_view :foo, "js file", :format => :js
74
+ mock_app do
75
+ get('/layout_test', :respond_to => [:html, :js]){ render :foo }
76
+ end
77
+ get "/layout_test"
78
+ assert_equal "this is an erb file", body
79
+ get "/layout_test.js"
80
+ assert_equal "js file", body
81
+ remove_views
82
+ end
83
+
84
+ should 'use correct layout for each format' do
85
+ create_layout :application, "this is an <%= yield %>"
86
+ create_layout :application, "document start <%= yield %> end", :format => :xml
87
+ create_view :foo, "erb file"
88
+ create_view :foo, "xml file", :format => :xml
89
+ mock_app do
90
+ get('/layout_test', :respond_to => [:html, :xml]){ render :foo }
91
+ end
92
+ get "/layout_test"
93
+ assert_equal "this is an erb file", body
94
+ get "/layout_test.xml"
95
+ assert_equal "document start xml file end", body
96
+ remove_views
97
+ end
98
+ end
99
+
100
+ context 'for application render functionality' do
101
+
102
+ should 'be compatible with sinatra render' do
103
+ mock_app do
104
+ get("/"){ render :erb, "<%= 1+2 %>" }
105
+ end
106
+ get "/"
107
+ assert_equal "3", body
108
+ end
109
+
110
+ should 'be compatible with sinatra views' do
111
+ with_view :index, "<%= 1+2 %>" do
112
+ mock_app do
113
+ get("/foo") { render :erb, :index }
114
+ get("/bar") { erb :index }
115
+ get("/dir") { "3" }
116
+ get("/inj") { erb "<%= 2+1 %>" }
117
+ get("/rnj") { render :erb, "<%= 2+1 %>" }
118
+ end
119
+ get "/foo"
120
+ assert_equal "3", body
121
+ get "/bar"
122
+ assert_equal "3", body
123
+ get "/dir"
124
+ assert_equal "3", body
125
+ get "/inj"
126
+ assert_equal "3", body
127
+ get "/rnj"
128
+ assert_equal "3", body
129
+ end
130
+ end
131
+
132
+ should 'resolve template engine' do
133
+ with_view :index, "<%= 1+2 %>" do
134
+ mock_app do
135
+ get("/foo") { render :index }
136
+ get("/bar") { render "/index" }
137
+ end
138
+ get "/foo"
139
+ assert_equal "3", body
140
+ get "/bar"
141
+ assert_equal "3", body
142
+ end
143
+ end
144
+
145
+ should 'resolve template content type' do
146
+ create_view :foo, "Im Js", :format => :js
147
+ create_view :foo, "Im Erb"
148
+ mock_app do
149
+ get("/foo", :respond_to => :js) { render :foo }
150
+ get("/bar.js") { render :foo }
151
+ end
152
+ get "/foo.js"
153
+ assert_equal "Im Js", body
154
+ get "/bar.js"
155
+ assert_equal "Im Js", body
156
+ remove_views
157
+ end
158
+
159
+ should 'resolve with explicit template format' do
160
+ create_view :foo, "Im Js", :format => :js
161
+ create_view :foo, "Im Haml", :format => :haml
162
+ create_view :foo, "Im Xml", :format => :xml
163
+ mock_app do
164
+ get("/foo_normal", :respond_to => :js) { render 'foo' }
165
+ get("/foo_haml", :respond_to => :js) { render 'foo.haml' }
166
+ get("/foo_xml", :respond_to => :js) { render 'foo.xml' }
167
+ end
168
+ get "/foo_normal.js"
169
+ assert_equal "Im Js", body
170
+ get "/foo_haml.js"
171
+ assert_equal "Im Haml\n", body
172
+ get "/foo_xml.js"
173
+ assert_equal "Im Xml", body
174
+ remove_views
175
+ end
176
+
177
+ should "ignore files ending in tilde and not render them" do
178
+ create_view :foo, "Im Wrong", :format => 'haml~'
179
+ create_view :foo, "Im Haml", :format => :haml
180
+ create_view :bar, "Im Haml backup", :format => 'haml~'
181
+ mock_app do
182
+ get('/foo') { render 'foo' }
183
+ get('/bar') { render 'bar' }
184
+ end
185
+ get '/foo'
186
+ assert_equal "Im Haml\n", body
187
+ assert_raises(Padrino::Rendering::TemplateNotFound) { get '/bar' }
188
+ remove_views
189
+ end
190
+
191
+ should 'resolve template locale' do
192
+ create_view :foo, "Im English", :locale => :en
193
+ create_view :foo, "Im Italian", :locale => :it
194
+ mock_app do
195
+ get("/foo") { render :foo }
196
+ end
197
+ I18n.locale = :en
198
+ get "/foo"
199
+ assert_equal "Im English", body
200
+ I18n.locale = :it
201
+ get "/foo"
202
+ assert_equal "Im Italian", body
203
+ end
204
+
205
+ should 'resolve template content_type and locale' do
206
+ create_view :foo, "Im Js", :format => :js
207
+ create_view :foo, "Im Erb"
208
+ create_view :foo, "Im English Erb", :locale => :en
209
+ create_view :foo, "Im Italian Erb", :locale => :it
210
+ create_view :foo, "Im English Js", :format => :js, :locale => :en
211
+ create_view :foo, "Im Italian Js", :format => :js, :locale => :it
212
+ mock_app do
213
+ get("/foo", :respond_to => [:html, :js]) { render :foo }
214
+ end
215
+ I18n.locale = :none
216
+ get "/foo.js"
217
+ assert_equal "Im Js", body
218
+ get "/foo"
219
+ assert_equal "Im Erb", body
220
+ I18n.locale = :en
221
+ get "/foo"
222
+ assert_equal "Im English Erb", body
223
+ I18n.locale = :it
224
+ get "/foo"
225
+ assert_equal "Im Italian Erb", body
226
+ I18n.locale = :en
227
+ get "/foo.js"
228
+ assert_equal "Im English Js", body
229
+ I18n.locale = :it
230
+ get "/foo.js"
231
+ assert_equal "Im Italian Js", body
232
+ I18n.locale = :en
233
+ get "/foo.pk"
234
+ assert_equal 404, status
235
+ end
236
+
237
+ should 'resolve template content_type and locale with layout' do
238
+ create_layout :foo, "Hello <%= yield %> in a Js layout", :format => :js
239
+ create_layout :foo, "Hello <%= yield %> in a Js-En layout", :format => :js, :locale => :en
240
+ create_layout :foo, "Hello <%= yield %> in a Js-It layout", :format => :js, :locale => :it
241
+ create_layout :foo, "Hello <%= yield %> in a Erb-En layout", :locale => :en
242
+ create_layout :foo, "Hello <%= yield %> in a Erb-It layout", :locale => :it
243
+ create_layout :foo, "Hello <%= yield %> in a Erb layout"
244
+ create_view :bar, "Im Js", :format => :js
245
+ create_view :bar, "Im Erb"
246
+ create_view :bar, "Im English Erb", :locale => :en
247
+ create_view :bar, "Im Italian Erb", :locale => :it
248
+ create_view :bar, "Im English Js", :format => :js, :locale => :en
249
+ create_view :bar, "Im Italian Js", :format => :js, :locale => :it
250
+ create_view :bar, "Im a json", :format => :json
251
+ mock_app do
252
+ layout :foo
253
+ get("/bar", :respond_to => [:html, :js, :json]) { render :bar }
254
+ end
255
+ I18n.locale = :none
256
+ get "/bar.js"
257
+ assert_equal "Hello Im Js in a Js layout", body
258
+ get "/bar"
259
+ assert_equal "Hello Im Erb in a Erb layout", body
260
+ I18n.locale = :en
261
+ get "/bar"
262
+ assert_equal "Hello Im English Erb in a Erb-En layout", body
263
+ I18n.locale = :it
264
+ get "/bar"
265
+ assert_equal "Hello Im Italian Erb in a Erb-It layout", body
266
+ I18n.locale = :en
267
+ get "/bar.js"
268
+ assert_equal "Hello Im English Js in a Js-En layout", body
269
+ I18n.locale = :it
270
+ get "/bar.js"
271
+ assert_equal "Hello Im Italian Js in a Js-It layout", body
272
+ I18n.locale = :en
273
+ get "/bar.json"
274
+ assert_equal "Im a json", body
275
+ get "/bar.pk"
276
+ assert_equal 404, status
277
+ end
278
+
279
+ should 'renders erb with blocks' do
280
+ mock_app do
281
+ def container
282
+ @_out_buf << "THIS."
283
+ yield
284
+ @_out_buf << "SPARTA!"
285
+ end
286
+ def is; "IS."; end
287
+ get '/' do
288
+ render :erb, '<% container do %> <%= is %> <% end %>'
289
+ end
290
+ end
291
+ get '/'
292
+ assert ok?
293
+ assert_equal 'THIS. IS. SPARTA!', body
294
+ end
295
+ end
296
+
297
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  class TestRouting < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
3
  module Rack::Handler
4
4
  class Mock
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 7
9
- version: 0.9.7
8
+ - 9
9
+ version: 0.9.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Padrino Team
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-03-22 00:00:00 -07:00
20
+ date: 2010-03-29 00:00:00 -07:00
21
21
  default_executable: padrino
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -28,10 +28,10 @@ dependencies:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  segments:
31
+ - 1
31
32
  - 0
32
- - 9
33
- - 6
34
- version: 0.9.6
33
+ - 0
34
+ version: 1.0.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -160,6 +160,20 @@ dependencies:
160
160
  version: 0.5.1
161
161
  type: :development
162
162
  version_requirements: *id010
163
+ - !ruby/object:Gem::Dependency
164
+ name: haml
165
+ prerelease: false
166
+ requirement: &id011 !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ segments:
171
+ - 2
172
+ - 2
173
+ - 22
174
+ version: 2.2.22
175
+ type: :development
176
+ version_requirements: *id011
163
177
  description: The Padrino core gem required for use of this framework
164
178
  email: padrinorb@gmail.com
165
179
  executables:
@@ -215,6 +229,7 @@ files:
215
229
  - test/test_mounter.rb
216
230
  - test/test_reloader_complex.rb
217
231
  - test/test_reloader_simple.rb
232
+ - test/test_rendering.rb
218
233
  - test/test_routing.rb
219
234
  - test/test_server.rb
220
235
  has_rdoc: true