deas 0.6.0 → 0.7.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.
data/README.md CHANGED
@@ -4,7 +4,30 @@ Handler-based web framework powered by Sinatra.
4
4
 
5
5
  ## Usage
6
6
 
7
- TODO: Write code samples and usage instructions here
7
+ ```ruby
8
+ # in your rackup file (or whatever)
9
+
10
+ require 'deas'
11
+
12
+ class MyApp
13
+ include Deas::Server
14
+
15
+ get '/', 'HelloWorldHandler'
16
+
17
+ end
18
+
19
+ class HellowWorldHandler
20
+ include Deas::ViewHandler
21
+
22
+ def run!
23
+ "<h1>Hello World</h1>"
24
+ end
25
+
26
+ end
27
+
28
+ app = MyApp.new
29
+ run app
30
+ ```
8
31
 
9
32
  ## Installation
10
33
 
data/deas.gemspec CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency("rack", ["~> 1.5"])
22
22
  gem.add_dependency("sinatra", ["~> 1.4"])
23
23
 
24
- gem.add_development_dependency("assert", ["~> 2.0"])
25
- gem.add_development_dependency("assert-mocha", ["~> 1.0"])
26
- gem.add_development_dependency("rack-test", ["~> 0.6"])
24
+ gem.add_development_dependency("assert")
25
+ gem.add_development_dependency("assert-mocha")
26
+ gem.add_development_dependency("assert-rack-test")
27
27
 
28
28
  end
data/lib/deas.rb CHANGED
@@ -3,39 +3,13 @@ require 'pathname'
3
3
 
4
4
  require 'deas/version'
5
5
  require 'deas/server'
6
- require 'deas/sinatra_app'
7
6
  require 'deas/view_handler'
8
7
 
9
8
  # TODO - remove with future version of Rack (> v1.5.2)
10
9
  require 'deas/rack_request_fix'
11
10
 
12
- ENV['DEAS_ROUTES_FILE'] ||= 'config/routes'
13
-
14
11
  module Deas
15
12
 
16
- def self.app
17
- @app
18
- end
19
-
20
- def self.config
21
- Deas::Config
22
- end
23
-
24
- def self.configure(&block)
25
- self.config.define(&block)
26
- self.config
27
- end
28
-
29
- def self.init
30
- require self.config.routes_file
31
- @app = Deas::SinatraApp.new(Deas::Server.configuration)
32
- end
33
-
34
- module Config
35
- include NsOptions::Proxy
36
- option :routes_file, Pathname, :default => ENV['DEAS_ROUTES_FILE']
37
- end
38
-
39
13
  class NullLogger
40
14
  require 'logger'
41
15
 
data/lib/deas/logging.rb CHANGED
@@ -13,7 +13,7 @@ module Deas
13
13
 
14
14
  def initialize(app)
15
15
  @app = app
16
- @logger = Deas.app.settings.logger
16
+ @logger = @app.settings.logger
17
17
  end
18
18
 
19
19
  # The Rack call interface. The receiver acts as a prototype and runs
data/lib/deas/server.rb CHANGED
@@ -1,59 +1,74 @@
1
1
  require 'ns-options'
2
2
  require 'ns-options/boolean'
3
3
  require 'pathname'
4
- require 'singleton'
4
+ require 'deas/template'
5
5
  require 'deas/route'
6
+ require 'deas/sinatra_app'
6
7
 
7
- module Deas
8
-
9
- class Server
10
- include Singleton
11
-
12
- class Configuration
13
- include NsOptions::Proxy
14
-
15
- # Sinatra based options
16
- option :env, String, :default => 'development'
17
- option :root, Pathname, :default => proc{ File.dirname(Deas.config.routes_file) }
18
-
19
- option :app_file, Pathname, :default => proc{ Deas.config.routes_file }
20
- option :public_folder, Pathname
21
- option :views_folder, Pathname
22
-
23
- option :dump_errors, NsOptions::Boolean, :default => false
24
- option :method_override, NsOptions::Boolean, :default => true
25
- option :sessions, NsOptions::Boolean, :default => false
26
- option :show_exceptions, NsOptions::Boolean, :default => false
27
- option :static_files, NsOptions::Boolean, :default => true
28
- option :reload_templates, NsOptions::Boolean, :default => false
29
-
30
- # server handling options
31
- option :error_procs, Array, :default => []
32
- option :init_procs, Array, :default => []
33
- option :logger, :default => proc{ Deas::NullLogger.new }
34
- option :middlewares, Array, :default => []
35
- option :verbose_logging, :default => true
36
-
37
- option :routes, Array, :default => []
38
- option :view_handler_ns, String
39
-
40
- def initialize
41
- # these are defaulted here because we want to use the Configuration
42
- # instance `root`. If we define a proc above, we will be using the
43
- # Configuration class `root`, which will not update these options as
44
- # expected.
45
- super({
46
- :public_folder => proc{ self.root.join('public') },
47
- :views_folder => proc{ self.root.join('views') }
48
- })
49
- end
8
+ module Deas; end
9
+ module Deas::Server
50
10
 
51
- end
11
+ class Configuration
12
+ include NsOptions::Proxy
13
+
14
+ # Sinatra based options
15
+ option :env, String, :default => 'development'
16
+
17
+ option :root, Pathname
18
+ option :public_folder, Pathname
19
+ option :views_folder, Pathname
20
+
21
+ option :dump_errors, NsOptions::Boolean, :default => false
22
+ option :method_override, NsOptions::Boolean, :default => true
23
+ option :sessions, NsOptions::Boolean, :default => false
24
+ option :show_exceptions, NsOptions::Boolean, :default => false
25
+ option :static_files, NsOptions::Boolean, :default => true
26
+ option :reload_templates, NsOptions::Boolean, :default => false
27
+
28
+ # server handling options
29
+ option :error_procs, Array, :default => []
30
+ option :init_procs, Array, :default => []
31
+ option :logger, :default => proc{ Deas::NullLogger.new }
32
+ option :middlewares, Array, :default => []
33
+ option :settings, Array, :default => []
34
+ option :verbose_logging, :default => true
35
+ option :routes, Array, :default => []
36
+ option :view_handler_ns, String
52
37
 
53
- attr_reader :configuration
38
+ attr_reader :template_helpers
54
39
 
55
40
  def initialize
56
- @configuration = Configuration.new
41
+ # these are defaulted here because we want to use the Configuration
42
+ # instance `root`. If we define a proc above, we will be using the
43
+ # Configuration class `root`, which will not update these options as
44
+ # expected.
45
+ super({
46
+ :public_folder => proc{ self.root.join('public') },
47
+ :views_folder => proc{ self.root.join('views') }
48
+ })
49
+ @template_helpers = []
50
+ end
51
+
52
+ def template_scope
53
+ Class.new(Deas::Template::Scope).tap do |klass|
54
+ klass.send(:include, *self.template_helpers)
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ def self.included(receiver)
61
+ receiver.class_eval{ extend ClassMethods }
62
+ end
63
+
64
+ module ClassMethods
65
+
66
+ def new
67
+ Deas::SinatraApp.new(self.configuration)
68
+ end
69
+
70
+ def configuration
71
+ @configuration ||= Configuration.new
57
72
  end
58
73
 
59
74
  # sinatra settings DSL
@@ -100,28 +115,41 @@ module Deas
100
115
 
101
116
  # Server handling DSL
102
117
 
103
- def error(&block)
104
- self.configuration.error_procs << block
105
- end
106
-
107
118
  def init(&block)
108
119
  self.configuration.init_procs << block
109
120
  end
110
121
 
122
+ def template_helpers(*helper_modules)
123
+ helper_modules.each{ |m| self.configuration.template_helpers << m }
124
+ self.configuration.template_helpers
125
+ end
126
+
127
+ def template_helper?(helper_module)
128
+ self.configuration.template_helpers.include?(helper_module)
129
+ end
130
+
131
+ def error(&block)
132
+ self.configuration.error_procs << block
133
+ end
134
+
111
135
  def logger(*args)
112
136
  self.configuration.logger *args
113
137
  end
114
138
 
115
- def verbose_logging(*args)
116
- self.configuration.verbose_logging *args
139
+ def use(*args)
140
+ self.configuration.middlewares << args
141
+ end
142
+
143
+ def set(*args)
144
+ self.configuration.settings << args
117
145
  end
118
146
 
119
147
  def view_handler_ns(*args)
120
148
  self.configuration.view_handler_ns *args
121
149
  end
122
150
 
123
- def use(*args)
124
- self.configuration.middlewares << args
151
+ def verbose_logging(*args)
152
+ self.configuration.verbose_logging *args
125
153
  end
126
154
 
127
155
  def get(path, handler_class_name)
@@ -153,14 +181,6 @@ module Deas
153
181
  end
154
182
  end
155
183
 
156
- def self.method_missing(method, *args, &block)
157
- self.instance.send(method, *args, &block)
158
- end
159
-
160
- def self.respond_to?(*args)
161
- super || self.instance.respond_to?(*args)
162
- end
163
-
164
184
  end
165
185
 
166
186
  end
@@ -19,7 +19,6 @@ module Deas
19
19
  set :environment, server_config.env
20
20
  set :root, server_config.root
21
21
 
22
- set :app_file, server_config.app_file
23
22
  set :public_folder, server_config.public_folder
24
23
  set :views, server_config.views_folder
25
24
 
@@ -29,21 +28,20 @@ module Deas
29
28
  set :show_exceptions, server_config.show_exceptions
30
29
  set :static, server_config.static_files
31
30
  set :reload_templates, server_config.reload_templates
32
- set :logging, false
31
+ set :logging, false
33
32
 
34
33
  # custom settings
35
- set :deas_error_procs, server_config.error_procs
36
- set :logger, server_config.logger
34
+ set :deas_template_scope, server_config.template_scope
35
+ set :deas_error_procs, server_config.error_procs
36
+ set :logger, server_config.logger
37
+
38
+ server_config.settings.each{ |set_args| set *set_args }
39
+ server_config.middlewares.each{ |use_args| use *use_args }
37
40
 
38
- server_config.middlewares.each do |middleware_args|
39
- use *middleware_args
40
- end
41
41
  use Deas::Logging.middleware(server_config.verbose_logging)
42
42
 
43
43
  # routes
44
44
  server_config.routes.each do |route|
45
- # defines Sinatra routes like:
46
- # get('/'){ ... }
47
45
  send(route.method, route.path){ route.run(self) }
48
46
  end
49
47
 
data/lib/deas/template.rb CHANGED
@@ -4,35 +4,25 @@ module Deas
4
4
 
5
5
  class Template
6
6
 
7
- def self.helpers(*helper_modules)
8
- Deas::Template::RenderScope.class_eval{ include *helper_modules }
9
- end
10
-
11
- def self.helper?(helper_module)
12
- Deas::Template::RenderScope.included_modules.include?(helper_module)
13
- end
14
-
15
7
  attr_reader :name, :options
16
8
 
17
9
  def initialize(sinatra_call, name, options = nil)
18
- @options = options || {}
19
- @options[:scope] = RenderScope.new(sinatra_call)
10
+ @sinatra_call, @name, @options = sinatra_call, name.to_sym, (options || {})
11
+ @options[:scope] = @sinatra_call.settings.deas_template_scope.new(@sinatra_call)
20
12
 
21
- @sinatra_call = sinatra_call
22
- @name = name.to_sym
23
13
  (@options.delete(:layout) || @options.delete(:layouts) || []).tap do |l|
24
14
  @layouts = l.compact.map(&:to_sym)
25
15
  end
26
16
  end
27
17
 
28
- # builds Sinatra render-blocks like:
18
+ # builds render-blocks like:
29
19
  #
30
20
  # erb :main_layout do
31
21
  # erb :second_layout do
32
22
  # erb :user_index
33
23
  # end
34
24
  # end
35
- #
25
+
36
26
  def render(&block)
37
27
  template_names = [ @layouts, @name ].flatten.reverse
38
28
  top_render_proc = template_names.inject(block) do |render_proc, name|
@@ -41,17 +31,18 @@ module Deas
41
31
  top_render_proc.call
42
32
  end
43
33
 
44
- class RenderScope
34
+ class Scope
35
+ attr_reader :sinatra_call
45
36
  def initialize(sinatra_call)
46
37
  @sinatra_call = sinatra_call
47
38
  end
48
39
 
49
40
  def render(name, options = nil, &block)
50
- Deas::Template.new(@sinatra_call, name, options || {}).render(&block)
41
+ Template.new(@sinatra_call, name, options || {}).render(&block)
51
42
  end
52
43
 
53
44
  def partial(name, locals = nil)
54
- Deas::Partial.new(@sinatra_call, name, locals || {}).render
45
+ Partial.new(@sinatra_call, name, locals || {}).render
55
46
  end
56
47
 
57
48
  def escape_html(html)
@@ -64,19 +55,23 @@ module Deas
64
55
  end
65
56
  alias :u :escape_url
66
57
 
58
+ def ==(other_scope)
59
+ self.sinatra_call == other_scope.sinatra_call
60
+ self.class.included_modules == other_scope.class.included_modules
61
+ end
67
62
  end
68
63
 
69
- end
64
+ class Partial < Template
70
65
 
71
- class Partial < Template
72
-
73
- def initialize(sinatra_call, name, locals = nil)
74
- options = { :locals => (locals || {}) }
75
- name = begin
76
- basename = File.basename(name.to_s)
77
- name.to_s.sub(/#{basename}\Z/, "_#{basename}")
66
+ def initialize(sinatra_call, name, locals = nil)
67
+ options = { :locals => (locals || {}) }
68
+ name = begin
69
+ basename = File.basename(name.to_s)
70
+ name.to_s.sub(/#{basename}\Z/, "_#{basename}")
71
+ end
72
+ super sinatra_call, name, options
78
73
  end
79
- super sinatra_call, name, options
74
+
80
75
  end
81
76
 
82
77
  end
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -39,6 +39,10 @@ module Deas
39
39
  "#<#{self.class}:#{reference} @request=#{self.request.inspect}>"
40
40
  end
41
41
 
42
+ def ==(other_handler)
43
+ self.class == other_handler.class
44
+ end
45
+
42
46
  protected
43
47
 
44
48
  # Helpers
data/test/helper.rb CHANGED
@@ -2,15 +2,20 @@
2
2
  # put any test helpers here
3
3
 
4
4
  # add the root dir to the load path
5
- ROOT = File.expand_path('../..', __FILE__)
6
- $LOAD_PATH.unshift(ROOT)
5
+ require 'pathname'
6
+ ROOT = Pathname.new(File.expand_path('../..', __FILE__))
7
+ $LOAD_PATH.unshift(ROOT.to_s)
8
+ TEST_SUPPORT_ROOT = ROOT.join('test/support')
7
9
 
8
10
  # require pry for debugging (`binding.pry`)
9
11
  require 'pry'
10
12
  require 'assert-mocha' if defined?(Assert)
11
13
 
12
- require 'deas'
13
- Deas.configure do |config|
14
- config.routes_file = File.join(ROOT, 'test/support/routes')
15
- end
16
- Deas.init
14
+ require 'fileutils'
15
+ require 'logger'
16
+ log_file_path = ROOT.join("log/test.log")
17
+ FileUtils.rm_f log_file_path
18
+ TEST_LOGGER = Logger.new(File.open(log_file_path, 'w'))
19
+
20
+ require TEST_SUPPORT_ROOT.join('routes')
21
+
@@ -13,18 +13,19 @@ class FakeApp
13
13
  @params = @request.params
14
14
  @session = @request.session
15
15
  @response = FakeResponse.new
16
- @settings = OpenStruct.new({ })
16
+ @settings = OpenStruct.new(:deas_template_scope => Deas::Template::Scope)
17
17
  end
18
18
 
19
19
  def halt(*args)
20
20
  throw :halt, args
21
21
  end
22
22
 
23
- def erb(*args, &block)
23
+ # return the template name for each nested calls
24
+ def erb(name, opts, &block)
24
25
  if block
25
- [ args, block.call ].flatten
26
+ [ name, opts, block.call ].flatten
26
27
  else
27
- args
28
+ [ name, opts ]
28
29
  end
29
30
  end
30
31
 
@@ -1,12 +1,11 @@
1
1
  require 'deas'
2
2
 
3
- class Deas::Server
3
+ class DeasTestServer
4
+ include Deas::Server
4
5
 
5
- root File.expand_path("..", __FILE__)
6
+ root TEST_SUPPORT_ROOT
6
7
 
7
- log_file_path = File.expand_path("../../../log/test.log", __FILE__)
8
-
9
- logger Logger.new(File.open(log_file_path, 'w'))
8
+ logger TEST_LOGGER
10
9
  verbose_logging true
11
10
 
12
11
  error do |exception|
@@ -1,14 +1,15 @@
1
1
  require 'assert'
2
- require 'rack/test'
2
+ require 'assert-rack-test'
3
+ require 'deas'
3
4
 
4
5
  module Deas
5
6
 
6
7
  class RackTests < Assert::Context
7
- include Rack::Test::Methods
8
+ include Assert::Rack::Test
8
9
 
9
- desc "Deas' the rack app"
10
+ desc "a Deas server rack app"
10
11
  setup do
11
- @app = Deas.app.new
12
+ @app = DeasTestServer.new
12
13
  end
13
14
 
14
15
  def app; @app; end
@@ -76,10 +77,11 @@ module Deas
76
77
  class SessionTests < RackTests
77
78
  desc "with sessions enabled"
78
79
  setup do
79
- orig_sessions = Deas.app.settings.sessions
80
- Deas.app.set :sessions, true
81
- @app = Deas.app.new
82
- Deas.app.set :sessions, orig_sessions
80
+ @orig_sessions = @app.settings.sessions
81
+ @app.set :sessions, true
82
+ end
83
+ teardown do
84
+ @app.set :sessions, @orig_sessions
83
85
  end
84
86
 
85
87
  should "return a 200 response and the session value" do
@@ -1,20 +1,24 @@
1
1
  require 'assert'
2
+ require 'test/support/fake_app'
2
3
  require 'deas/logging'
3
4
 
4
5
  module Deas::Logging
5
6
 
6
7
  class BaseTests < Assert::Context
7
8
  desc "Deas::Logging"
9
+ setup do
10
+ @app = FakeApp.new
11
+ end
8
12
  subject{ Deas::Logging }
9
13
 
10
14
  should have_imeths :middleware
11
15
 
12
16
  end
13
17
 
14
- class VerboseLoggingTests < Assert::Context
18
+ class VerboseLoggingTests < BaseTests
15
19
  desc "Deas::VerboseLogging"
16
20
  setup do
17
- @middleware = Deas::VerboseLogging.new('a rack app goes here')
21
+ @middleware = Deas::VerboseLogging.new(@app)
18
22
  end
19
23
  subject{ @middleware }
20
24
 
@@ -26,10 +30,10 @@ module Deas::Logging
26
30
 
27
31
  end
28
32
 
29
- class SummaryLoggingTests < Assert::Context
33
+ class SummaryLoggingTests < BaseTests
30
34
  desc "Deas::SummaryLogging"
31
35
  setup do
32
- @middleware = Deas::SummaryLogging.new('a rack app goes here')
36
+ @middleware = Deas::SummaryLogging.new(@app)
33
37
  end
34
38
  subject{ @middleware }
35
39
 
@@ -41,7 +45,7 @@ module Deas::Logging
41
45
 
42
46
  end
43
47
 
44
- class SummaryLineTests < Assert::Context
48
+ class SummaryLineTests < BaseTests
45
49
  desc "Deas::SummaryLine"
46
50
  subject{ Deas::SummaryLine }
47
51
 
@@ -1,27 +1,19 @@
1
1
  require 'assert'
2
+ require 'deas/template'
2
3
  require 'deas/route'
3
4
  require 'deas/server'
4
5
  require 'logger'
5
6
 
6
- class Deas::Server
7
+ module Deas::Server
7
8
 
8
9
  class BaseTests < Assert::Context
9
10
  desc "Deas::Server"
10
11
  setup do
11
- @old_configuration = Deas::Server.configuration.dup
12
- new_configuration = Deas::Server::Configuration.new
13
- Deas::Server.instance.tap do |s|
14
- s.instance_variable_set("@configuration", new_configuration)
15
- end
12
+ @server_class = Class.new{ include Deas::Server }
16
13
  end
17
- teardown do
18
- Deas::Server.instance.tap do |s|
19
- s.instance_variable_set("@configuration", @old_configuration)
20
- end
21
- end
22
- subject{ Deas::Server }
14
+ subject{ @server_class }
23
15
 
24
- should have_reader :configuration
16
+ should have_imeths :new, :configuration
25
17
 
26
18
  # DSL for sinatra settings
27
19
  should have_imeths :env, :root, :public_folder, :views_folder
@@ -29,13 +21,10 @@ class Deas::Server
29
21
  should have_imeths :static_files, :reload_templates
30
22
 
31
23
  # DSL for server handling
32
- should have_imeths :init, :logger, :use, :view_handler_ns, :use
24
+ should have_imeths :init, :template_helpers, :template_helper?, :error
25
+ should have_imeths :logger, :use, :set, :view_handler_ns, :verbose_logging
33
26
  should have_imeths :get, :post, :put, :patch, :delete, :route
34
27
 
35
- should "be a singleton" do
36
- assert_includes Singleton, subject.included_modules
37
- end
38
-
39
28
  should "allow setting it's configuration options" do
40
29
  config = subject.configuration
41
30
 
@@ -72,6 +61,9 @@ class Deas::Server
72
61
  subject.use 'MyMiddleware'
73
62
  assert_equal [ ['MyMiddleware'] ], config.middlewares
74
63
 
64
+ subject.set :testing_set_meth, 'it works!'
65
+ assert_equal [ [:testing_set_meth, 'it works!'] ], config.settings
66
+
75
67
  stdout_logger = Logger.new(STDOUT)
76
68
  subject.logger stdout_logger
77
69
  assert_equal stdout_logger, config.logger
@@ -159,6 +151,11 @@ class Deas::Server
159
151
  assert_equal '::NoNsTest', route.handler_class_name
160
152
  end
161
153
 
154
+ should "add and query helper modules using #template_helpers and #template_helper?" do
155
+ subject.template_helpers (helper_module = Module.new)
156
+ assert subject.template_helper?(helper_module)
157
+ end
158
+
162
159
  end
163
160
 
164
161
  class ConfigurationTests < BaseTests
@@ -169,37 +166,25 @@ class Deas::Server
169
166
  subject{ @configuration }
170
167
 
171
168
  # sinatra related options
172
- should have_imeths :env, :root, :app_file, :public_folder, :views_folder
169
+ should have_imeths :env, :root, :public_folder, :views_folder
173
170
  should have_imeths :dump_errors, :method_override, :sessions, :show_exceptions
174
171
  should have_imeths :static_files, :reload_templates
175
172
 
176
173
  # server handling options
177
- should have_imeths :init_procs, :logger, :verbose_logging, :middlewares
178
- should have_imeths :routes, :view_handler_ns
174
+ should have_imeths :error_procs, :init_procs, :logger, :middlewares, :settings
175
+ should have_imeths :verbose_logging, :routes, :view_handler_ns
176
+
177
+ should have_reader :template_helpers
179
178
 
180
179
  should "default the env to 'development'" do
181
180
  assert_equal 'development', subject.env
182
181
  end
183
182
 
184
- should "default the root to the routes file's folder" do
185
- expected_root = File.expand_path('..', Deas.config.routes_file)
186
- assert_equal expected_root, subject.root.to_s
187
- end
188
-
189
- should "default the app file to the routes file" do
190
- assert_equal Deas.config.routes_file.to_s, subject.app_file.to_s
191
- end
183
+ should "default the public and views folders based off the root" do
184
+ subject.root = TEST_SUPPORT_ROOT
192
185
 
193
- should "default the public folder based on the root" do
194
- expected_root = File.expand_path('..', Deas.config.routes_file)
195
- expected_public_folder = File.join(expected_root, 'public')
196
- assert_equal expected_public_folder, subject.public_folder.to_s
197
- end
198
-
199
- should "default the views folder based on the root" do
200
- expected_root = File.expand_path('..', Deas.config.routes_file)
201
- expected_views_folder = File.join(expected_root, 'views')
202
- assert_equal expected_views_folder, subject.views_folder.to_s
186
+ assert_equal subject.root.join('public'), subject.public_folder
187
+ assert_equal subject.root.join('views'), subject.views_folder
203
188
  end
204
189
 
205
190
  should "default the Sinatra flags" do
@@ -211,16 +196,24 @@ class Deas::Server
211
196
  assert_equal false, subject.reload_templates
212
197
  end
213
198
 
214
- should "default the logger to a NullLogger" do
199
+ should "default the handling options" do
200
+ assert_empty subject.error_procs
201
+ assert_empty subject.init_procs
215
202
  assert_instance_of Deas::NullLogger, subject.logger
203
+ assert_empty subject.middlewares
204
+ assert_empty subject.settings
205
+ assert_equal true, subject.verbose_logging
206
+ assert_empty subject.routes
207
+ assert_nil subject.view_handler_ns
208
+ assert_empty subject.template_helpers
216
209
  end
217
210
 
218
- should "default routes to an empty array" do
219
- assert_equal [], subject.routes
220
- end
211
+ should "build a template scope including its template helpers" do
212
+ config = Deas::Server::Configuration.new
213
+ config.template_helpers << (helper_module = Module.new)
221
214
 
222
- should "default middlewares to an empty array" do
223
- assert_equal [], subject.middlewares
215
+ assert_includes Deas::Template::Scope, config.template_scope.ancestors
216
+ assert_includes helper_module, config.template_scope.included_modules
224
217
  end
225
218
 
226
219
  end
@@ -49,7 +49,6 @@ module Deas::SinatraApp
49
49
  subject.settings.tap do |settings|
50
50
  assert_equal 'staging', settings.environment
51
51
  assert_equal 'path/to/somewhere', settings.root.to_s
52
- assert_equal @configuration.app_file, settings.app_file
53
52
  assert_equal 'path/to/somewhere/public', settings.public_folder.to_s
54
53
  assert_equal 'path/to/somewhere/views', settings.views.to_s
55
54
  assert_equal true, settings.dump_errors
@@ -42,17 +42,15 @@ class Deas::SinatraRunner
42
42
  assert_equal [ 'test' ], return_value
43
43
  end
44
44
 
45
- should "call the sinatra_call's erb method with #render" do
46
- return_value = subject.render('index')
47
-
48
- assert_equal :web, return_value[0]
49
- assert_equal :index, return_value[2]
50
-
51
- options = return_value[3]
52
- assert_instance_of Deas::Template::RenderScope, options[:scope]
53
-
54
- expected_locals = { :view => subject.instance_variable_get("@handler") }
55
- assert_equal(expected_locals, options[:locals])
45
+ should "render the template with a :view local and the handler layouts with #render" do
46
+ exp_handler = FlagViewHandler.new(subject)
47
+ exp_layouts = FlagViewHandler.layouts
48
+ exp_result = Deas::Template.new(@fake_sinatra_call, 'index', {
49
+ :locals => { :view => exp_handler },
50
+ :layout => exp_layouts
51
+ }).render
52
+
53
+ assert_equal exp_result, subject.render('index')
56
54
  end
57
55
 
58
56
  should "call the sinatra_call's redirect method with #redirect" do
@@ -13,14 +13,13 @@ class Deas::Template
13
13
  subject{ @template }
14
14
 
15
15
  should have_instance_methods :name, :options, :render
16
- should have_class_methods :helpers, :helper?
17
16
 
18
17
  should "symbolize it's name" do
19
18
  assert_equal :"users/index", subject.name
20
19
  end
21
20
 
22
- should "set it's scope option to a empty Module" do
23
- assert_instance_of Deas::Template::RenderScope, subject.options[:scope]
21
+ should "set it's scope option" do
22
+ assert_instance_of Deas::Template::Scope, subject.options[:scope]
24
23
  end
25
24
 
26
25
  should "call the sinatra_call's `erb` method with #render" do
@@ -30,17 +29,6 @@ class Deas::Template
30
29
  assert_equal subject.options, return_value[1]
31
30
  end
32
31
 
33
- should "include modules on the RenderScope using `helpers` class method"\
34
- " and know if a given modules has been included in the RenderScope" do
35
- helper_module = Module.new
36
- Deas::Template.helpers(helper_module)
37
-
38
- included_modules = Deas::Template::RenderScope.included_modules
39
- assert_includes helper_module, included_modules
40
-
41
- assert Deas::Template.helper?(helper_module)
42
- end
43
-
44
32
  end
45
33
 
46
34
  class WithLayoutsTests < BaseTests
@@ -64,13 +52,12 @@ class Deas::Template
64
52
 
65
53
  end
66
54
 
67
- class RenderScopeTests < Assert::Context
55
+ class ScopeTests < BaseTests
68
56
  desc "Deas::Template::RenderScope"
69
57
  setup do
70
- @fake_sinatra_call = FakeApp.new
71
- @render_scope = Deas::Template::RenderScope.new(@fake_sinatra_call)
58
+ @scope = Deas::Template::Scope.new(@fake_sinatra_call)
72
59
  end
73
- subject{ @render_scope }
60
+ subject{ @scope }
74
61
 
75
62
  should have_imeths :partial, :escape_html, :h, :escape_url, :u, :render
76
63
 
@@ -80,7 +67,7 @@ class Deas::Template
80
67
  assert_equal :_part, return_value[0]
81
68
 
82
69
  expected_options = return_value[1]
83
- assert_instance_of Deas::Template::RenderScope, expected_options[:scope]
70
+ assert_instance_of Deas::Template::Scope, expected_options[:scope]
84
71
 
85
72
  expected_locals = { :something => true }
86
73
  assert_equal(expected_locals, expected_options[:locals])
@@ -89,15 +76,13 @@ class Deas::Template
89
76
  should "call the sinatra_call's erb method with #render" do
90
77
  return_value = subject.render('my_template', {
91
78
  :views => '/path/to/templates',
92
- :locals => {
93
- :something => true
94
- }
79
+ :locals => { :something => true }
95
80
  })
96
81
 
97
82
  assert_equal :my_template, return_value[0]
98
83
 
99
84
  expected_options = return_value[1]
100
- assert_instance_of Deas::Template::RenderScope, expected_options[:scope]
85
+ assert_instance_of Deas::Template::Scope, expected_options[:scope]
101
86
 
102
87
  expected_locals = { :something => true }
103
88
  assert_equal(expected_locals, expected_options[:locals])
@@ -121,15 +106,10 @@ class Deas::Template
121
106
 
122
107
  end
123
108
 
124
- end
125
-
126
- class Deas::Partial
127
-
128
- class BaseTests < Assert::Context
129
- desc "Deas::Partial"
109
+ class PartialTests < BaseTests
110
+ desc "Partial"
130
111
  setup do
131
- @fake_sinatra_call = FakeApp.new
132
- @partial = Deas::Partial.new(@fake_sinatra_call, 'users/index/listing', {
112
+ @partial = Deas::Template::Partial.new(@fake_sinatra_call, 'users/index/listing', {
133
113
  :user => 'Joe Test'
134
114
  })
135
115
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-05-10 00:00:00 Z
19
+ date: 2013-05-13 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: ns-options
@@ -77,13 +77,12 @@ dependencies:
77
77
  requirement: &id004 !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
80
- - - ~>
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  hash: 3
83
83
  segments:
84
- - 2
85
84
  - 0
86
- version: "2.0"
85
+ version: "0"
87
86
  type: :development
88
87
  version_requirements: *id004
89
88
  - !ruby/object:Gem::Dependency
@@ -92,28 +91,26 @@ dependencies:
92
91
  requirement: &id005 !ruby/object:Gem::Requirement
93
92
  none: false
94
93
  requirements:
95
- - - ~>
94
+ - - ">="
96
95
  - !ruby/object:Gem::Version
97
- hash: 15
96
+ hash: 3
98
97
  segments:
99
- - 1
100
98
  - 0
101
- version: "1.0"
99
+ version: "0"
102
100
  type: :development
103
101
  version_requirements: *id005
104
102
  - !ruby/object:Gem::Dependency
105
- name: rack-test
103
+ name: assert-rack-test
106
104
  prerelease: false
107
105
  requirement: &id006 !ruby/object:Gem::Requirement
108
106
  none: false
109
107
  requirements:
110
- - - ~>
108
+ - - ">="
111
109
  - !ruby/object:Gem::Version
112
- hash: 7
110
+ hash: 3
113
111
  segments:
114
112
  - 0
115
- - 6
116
- version: "0.6"
113
+ version: "0"
117
114
  type: :development
118
115
  version_requirements: *id006
119
116
  description: Handler-based web framework powered by Sinatra
@@ -158,8 +155,7 @@ files:
158
155
  - test/support/views/layout3.erb
159
156
  - test/support/views/show.erb
160
157
  - test/support/views/with_layout.erb
161
- - test/system/making_requests_tests.rb
162
- - test/unit/deas_tests.rb
158
+ - test/system/rack_tests.rb
163
159
  - test/unit/error_handler_tests.rb
164
160
  - test/unit/logging_tests.rb
165
161
  - test/unit/route_tests.rb
@@ -214,8 +210,7 @@ test_files:
214
210
  - test/support/views/layout3.erb
215
211
  - test/support/views/show.erb
216
212
  - test/support/views/with_layout.erb
217
- - test/system/making_requests_tests.rb
218
- - test/unit/deas_tests.rb
213
+ - test/system/rack_tests.rb
219
214
  - test/unit/error_handler_tests.rb
220
215
  - test/unit/logging_tests.rb
221
216
  - test/unit/route_tests.rb
@@ -1,21 +0,0 @@
1
- require 'assert'
2
- require 'deas'
3
-
4
- module Deas
5
-
6
- class BaseTests < Assert::Context
7
- desc "Deas"
8
- subject{ Deas }
9
-
10
- should have_instance_methods :config, :configure, :init, :app
11
-
12
- end
13
-
14
- class ConfigTests < BaseTests
15
- desc "Deas::Config"
16
- subject{ Deas::Config }
17
-
18
- should have_instance_methods :routes_file
19
- end
20
-
21
- end