tzispa 0.4.4 → 0.4.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f36c0edc3c28b95a144a74259cdbcc3f65a9f210
4
- data.tar.gz: 5b92e092f19b4d2bae342b44d9d87434cb1675fd
3
+ metadata.gz: aeeebb53345493217e8618fff6441a3c210b2f75
4
+ data.tar.gz: 958177f65207aac9c74e28fcfbdff7fe83609c61
5
5
  SHA512:
6
- metadata.gz: 7b183777adc2e2bd4eb1d69e65a9385c4954cb74ec35ae4c3969fa54a2e5397fb4f5d4da21983089436a689277d71d667b3963e8441338affdc9990e7a3cac2c
7
- data.tar.gz: 5183902dd4ace2c5e6fbc8dd69545f2c83116fca723cc87109e035771cd03a93745f8c135464bdf2b04f2c03945d16494054b84564ca428cecb59149f998a438
6
+ metadata.gz: 7c7f074552fd252f829f163e9ef49572a7f99340c31a344c05fe60c4e27ae51f725e91d8c6b3d4f267bc9ce631a393051a964a2195463e56757241f94d4f490c
7
+ data.tar.gz: 1fff97eec6fae0213afc1768baa7e9d0df5c21b4a24ac67c227191d9f614854e8fafc382a36bfc5870371311caf58bd46f60045af6a277fe674c544575d3e18a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@ Tzispa
2
2
 
3
3
  General purpose web framework
4
4
 
5
+ ## v0.4.5
6
+ - remove _load_assets_middleware
7
+ - add browser detection capability
8
+ - App environment constants names moved to app.rb
9
+ - code beautify
10
+ - Fix crash if there isn't any layout in http context
11
+ - Moved routes from Config namespace to Tzispa root
12
+ - Moved context creation from Controller::Base to Application::call
13
+ - code clean and organize
14
+
5
15
  ## v0.4.4
6
16
  - Add new template_cache config parameter
7
17
 
data/lib/tzispa/app.rb CHANGED
@@ -4,14 +4,20 @@ require 'forwardable'
4
4
  require 'logger'
5
5
  require 'i18n'
6
6
  require 'tzispa/domain'
7
+ require 'tzispa/routes'
7
8
  require 'tzispa/config/appconfig'
8
- require 'tzispa/config/routes'
9
9
  require 'tzispa/middleware'
10
+ require 'tzispa/http/context'
10
11
  require 'tzispa_data'
11
12
  require "tzispa_rig"
12
13
 
13
14
 
14
15
  module Tzispa
16
+
17
+ ENV_TZISPA_APP = :tzispa__app
18
+ ENV_TZISPA_CONTEXT = :tzispa__context
19
+
20
+
15
21
  class Application
16
22
  extend Forwardable
17
23
 
@@ -47,7 +53,7 @@ module Tzispa
47
53
 
48
54
  def mount(mount_point, builder)
49
55
  self.new.tap { |app|
50
- self.routes ||= Config::Routes.new(mount_point)
56
+ self.routes ||= Routes.new(mount_point)
51
57
  yield(routes)
52
58
  app.middleware.map mount_point, builder
53
59
  }
@@ -66,7 +72,8 @@ module Tzispa
66
72
  end
67
73
 
68
74
  def call(env)
69
- env[:tzispa__app] = self
75
+ env[Tzispa::ENV_TZISPA_APP] = self
76
+ env[Tzispa::ENV_TZISPA_CONTEXT] = Tzispa::Http::Context.new(env)
70
77
  middleware.call(env)
71
78
  end
72
79
 
@@ -96,6 +103,5 @@ module Tzispa
96
103
  end
97
104
  end
98
105
 
99
-
100
106
  end
101
107
  end
@@ -0,0 +1,110 @@
1
+ # This file extends the Kernel's require function and adds the
2
+ # AutoReload module which allows to reload files once they have changed
3
+ # on the disk.
4
+ #
5
+ # Basically, you just require your files as usual, and if you want to update
6
+ # the files, either call AutoReload.reload(file) or AutoReload.reload_all.
7
+ #
8
+ # Usage:
9
+ # irb -rautoload
10
+ #
11
+ # Then type 'reload' on the prompt to reload require'd files which have
12
+ # changed in the meantime.
13
+ #
14
+ # Written by Mikio L. Braun, March 16, 2008, edited Jan 15, 2010
15
+
16
+ require 'pp'
17
+ require 'set'
18
+
19
+ # This module tracks loaded files and their timestamps and allows to reload
20
+ # files which have changed automatically by calling reload.
21
+ module AutoReload
22
+ # stores the normalized filenames and their File.mtime timestamps
23
+ @timestamps = Hash.new
24
+ @notfound = Set.new
25
+ @verbose = false
26
+
27
+ def self.verbose=(flag)
28
+ @verbose = flag
29
+ end
30
+
31
+ # find the full path to a file
32
+ def self.locate(file)
33
+ return nil if @notfound.include? file
34
+ $:.each do |dir|
35
+ fullpath = File.join(dir, file)
36
+ if File.exists? fullpath
37
+ return fullpath
38
+ elsif File.exists?(fullpath + '.rb')
39
+ return fullpath + '.rb'
40
+ elsif File.exists?(fullpath + '.so')
41
+ return fullpath + '.so'
42
+ end
43
+ end
44
+ # puts "[AutoReload] File #{file} not found!"
45
+ @notfound.add file
46
+ return nil
47
+ end
48
+
49
+ # store the time stamp of a file
50
+ def self.timestamp(file)
51
+ path = locate(file)
52
+ if path
53
+ file = normalize(path, file)
54
+ @timestamps[file] = File.mtime(path)
55
+ end
56
+ end
57
+
58
+ # put the extension on a filename
59
+ def self.normalize(path, file)
60
+ if File.extname(file) == ""
61
+ return file + File.extname(path)
62
+ else
63
+ return file
64
+ end
65
+ end
66
+
67
+ # show all stored files and their timestamp
68
+ def self.dump
69
+ pp @timestamps
70
+ end
71
+
72
+ # reload a file
73
+ def self.reload(file, force=false)
74
+ path = locate(file)
75
+ file = normalize(path, file)
76
+
77
+ if force or (path and File.mtime(path) > @timestamps[file])
78
+ puts "[AutoReload] reloading #{file}" if @verbose
79
+
80
+ # delete file from list of loaded modules, and reload
81
+ $".delete file
82
+ require file
83
+ return true
84
+ else
85
+ return false
86
+ end
87
+ end
88
+
89
+ # reload all files which were required
90
+ def self.reload_all(force=false)
91
+ @timestamps.each_key do |file|
92
+ self.reload(file, force)
93
+ end
94
+ end
95
+ end
96
+
97
+ # Overwrite 'require' to register the time stamps instead.
98
+ module Kernel # :nodoc:
99
+ alias old_require require
100
+
101
+ def require(file)
102
+ AutoReload.timestamp(file)
103
+ old_require(file)
104
+ end
105
+
106
+ def reload
107
+ AutoReload.reload_all
108
+ return
109
+ end
110
+ end
@@ -7,16 +7,19 @@ module Tzispa
7
7
  class Context
8
8
  extend Forwardable
9
9
 
10
- attr_reader :app, :env, :repository
11
- def_delegators :@app, :config, :logger, :domain
10
+ attr_reader :env, :repository
11
+ def_delegators :app, :config, :logger, :domain
12
12
 
13
13
  def initialize(environment)
14
14
  @env = environment
15
- @app = environment[:tzispa__app]
16
- @repository = @app.repository.dup if @app.repository
15
+ @repository = app.repository.dup if app.repository
17
16
  I18n.locale = config.locales.default.to_sym if config.respond_to?(:locales)
18
17
  end
19
18
 
19
+ def app
20
+ @app ||= env[Tzispa::ENV_TZISPA_APP]
21
+ end
22
+
20
23
  end
21
24
 
22
25
  end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
- require 'ostruct'
5
4
  require 'tzispa/version'
6
- require 'tzispa/http/context'
7
5
  require 'tzispa/rig/template'
8
6
 
9
7
 
@@ -21,7 +19,7 @@ module Tzispa
21
19
  end
22
20
 
23
21
  def call(environment)
24
- @context = Tzispa::Http::Context.new(environment)
22
+ @context = environment[Tzispa::ENV_TZISPA_CONTEXT]
25
23
  invoke @callmethod if @callmethod
26
24
  response.finish
27
25
  end
@@ -67,7 +65,7 @@ module Tzispa
67
65
 
68
66
  def error_page(status)
69
67
  begin
70
- error_file = "#{@app.domain.path}/error/#{status}.htm"
68
+ error_file = "#{context.app.domain.path}/error/#{status}.htm"
71
69
  response.body = Tzispa::Rig::File.new(error_file).load!.content
72
70
  rescue
73
71
  response.body = String.new('<!DOCTYPE html>')
@@ -12,14 +12,8 @@ module Tzispa
12
12
  include Tzispa::Helpers::Response
13
13
 
14
14
  def render!
15
- layout = if context.config.auth_required && !context.logged? && context.router_params[:layout]
16
- context.config.default_layout
17
- else
18
- context.router_params[:layout] || context.config.default_layout
19
- end
20
15
  layout_format = context.router_params[:format] || context.config.default_format
21
- context.layout = layout
22
- rig = context.app.engine.layout(name: layout, format: layout_format.to_sym)
16
+ rig = context.app.engine.layout(name: layout_name, format: layout_format.to_sym)
23
17
  response.body << rig.render(context)
24
18
  content_type layout_format
25
19
  set_layout_headers
@@ -27,12 +21,21 @@ module Tzispa
27
21
 
28
22
  private
29
23
 
24
+ def layout_name
25
+ if config.auth_required && !context.logged? && context.layout
26
+ config.default_layout
27
+ else
28
+ context.layout || config.default_layout
29
+ end
30
+ end
31
+
32
+
30
33
  def set_layout_headers
31
34
  headers = Hash.new
32
- if context.app.config.cache.layout.enabled
33
- headers['Cache-Control'] = context.app.config.cache.layout.control
34
- if context.app.config.cache.layout.expires
35
- headers['Expires'] = (Time.now + context.app.config.cache.layout.expires).utc.rfc2822
35
+ if config.cache.layout.enabled
36
+ headers['Cache-Control'] = config.cache.layout.control
37
+ if config.cache.layout.expires
38
+ headers['Expires'] = (Time.now + config.cache.layout.expires).utc.rfc2822
36
39
  end
37
40
  end
38
41
  response.headers.merge!(headers)
@@ -16,7 +16,6 @@ module Tzispa
16
16
  include Tzispa::Helpers::Security
17
17
 
18
18
  attr_reader :request, :response
19
- attr_accessor :layout
20
19
  def_delegators :@request, :session
21
20
 
22
21
  SESSION_LAST_ACCESS = :__last_access
@@ -32,7 +31,11 @@ module Tzispa
32
31
  end
33
32
 
34
33
  def router_params
35
- @env['router.params']
34
+ env['router.params']
35
+ end
36
+
37
+ def layout
38
+ router_params&.fetch(:layout, nil)
36
39
  end
37
40
 
38
41
  def set_last_access
@@ -28,6 +28,76 @@ module Tzispa
28
28
  request_method == "UNLINK"
29
29
  end
30
30
 
31
+ def browser_is? name
32
+ name = name.to_s.strip
33
+ return true if browser_name == name
34
+ return true if name == 'mozilla' && browser_name == 'gecko'
35
+ return true if name == 'ie' && browser_name.index('ie')
36
+ return true if name == 'webkit' && %w{safari chrome iphone ipad ipod}.include?(browser_name)
37
+ return true if name == 'ios' && %w{iphone ipad ipod}.include?(browser_name)
38
+ return true if name == 'robots' && %w{googlebot msnbot yahoobot}.include?(browser_name)
39
+ end
40
+
41
+ # Returns the user agent string as determined by the plugin
42
+ def browser_name
43
+ @browser_name ||= begin
44
+ if user_agentindex('msie') && !user_agent.index('opera') && !user_agent.index('webtv')
45
+ 'ie'+user_agent[user_agent.index('msie')+5].chr
46
+ elsif user_agent.index('gecko/')
47
+ 'gecko'
48
+ elsif user_agent.index('opera')
49
+ 'opera'
50
+ elsif user_agent.index('konqueror')
51
+ 'konqueror'
52
+ elsif user_agent.index('ipod')
53
+ 'ipod'
54
+ elsif user_agent.index('ipad')
55
+ 'ipad'
56
+ elsif user_agent.index('iphone')
57
+ 'iphone'
58
+ elsif user_agent.index('chrome/')
59
+ 'chrome'
60
+ elsif user_agent.index('applewebkit/')
61
+ 'safari'
62
+ elsif user_agent.index('googlebot/')
63
+ 'googlebot'
64
+ elsif user_agent.index('msnbot')
65
+ 'msnbot'
66
+ elsif user_agent.index('yahoo! slurp')
67
+ 'yahoobot'
68
+ #Everything thinks it's mozilla, so this goes last
69
+ elsif user_agent.index('mozilla/')
70
+ 'gecko'
71
+ else
72
+ 'unknown'
73
+ end
74
+ end
75
+ end
76
+
77
+ # Determine the version of webkit.
78
+ # Useful for determing rendering capabilties
79
+ def browser_webkit_version
80
+ if browser_is? 'webkit'
81
+ match = user_agent.match(%r{\bapplewebkit/([\d\.]+)\b})
82
+ if (match)
83
+ match[1].to_f
84
+ else
85
+ nil
86
+ end
87
+ else
88
+ nil
89
+ end
90
+ end
91
+
92
+ #Gather the user agent and store it for use.
93
+ def user_agent
94
+ @ua ||= begin
95
+ @env['HTTP_USER_AGENT'].downcase
96
+ rescue
97
+ ''
98
+ end
99
+ end
100
+
31
101
  end
32
102
  end
33
103
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'moneta'
4
- require 'securerandom'
5
4
  require 'rack/session/moneta'
6
5
 
7
6
  module Tzispa
@@ -36,6 +35,8 @@ module Tzispa
36
35
  @stack.unshift [middleware, args, blk]
37
36
  end
38
37
 
38
+ private
39
+
39
40
  def load_middleware(middleware)
40
41
  case middleware
41
42
  when String
@@ -48,7 +49,6 @@ module Tzispa
48
49
  def load_default_stack
49
50
  @default_stack_loaded ||= begin
50
51
  _load_session_middleware
51
- _load_asset_middlewares
52
52
  use Rack::MethodOverride
53
53
  true
54
54
  end
@@ -66,17 +66,5 @@ module Tzispa
66
66
  end
67
67
  end
68
68
 
69
- def _load_asset_middlewares
70
- use Rack::Static,
71
- :urls => ["/img", "/js", "/css", "/*.ico"],
72
- :root => "public",
73
- :header_rules => [
74
- [:all, {'Cache-Control' => 'public, max-age=72000'}],
75
- ['css', {'Content-Type' => 'text/css; charset=utf-8'}],
76
- ['js', {'Content-Type' => 'text/javascript; charset=utf-8'}]
77
- ]
78
- end
79
-
80
-
81
69
  end
82
70
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'http_router'
5
+ require 'tzispa/utils/string'
6
+
7
+ module Tzispa
8
+
9
+ class Routes
10
+
11
+ CONTROLLERS_BASE = 'Tzispa::Controller'
12
+
13
+ attr_reader :router, :map_path
14
+
15
+ def initialize(map_path=nil)
16
+ @router = HttpRouter.new
17
+ @map_path = map_path unless map_path=='/'
18
+ end
19
+
20
+ def path(path_id, params={})
21
+ "#{@map_path}#{@router.path path_id, params}"
22
+ end
23
+
24
+ def add(route_id, path, controller, methods)
25
+ spec_control, callmethod = controller.to_s.split(':')
26
+ mpath = spec_control.split('#')
27
+ controller = TzString.camelize(mpath.pop).to_s
28
+ if mpath.count > 1
29
+ controller_module = mpath.collect!{ |w| w.capitalize }.join('::')
30
+ require_relative "./controller/#{controller.downcase}"
31
+ else
32
+ controller_module = CONTROLLERS_BASE
33
+ require "tzispa/controller/#{controller.downcase}"
34
+ end
35
+ @router.add(path, {request_method: methods}).tap { |rule|
36
+ rule.to TzString.constantize("#{controller_module}::#{controller}").new(callmethod)
37
+ rule.name = route_id
38
+ }
39
+ end
40
+
41
+ def index(path, methods, controller=nil)
42
+ add :index, path, controller || 'layout:render!', methods
43
+ end
44
+
45
+ def api(path, methods, controller=nil)
46
+ add :api, path, controller || 'api:dispatch!', methods
47
+ end
48
+
49
+ def site(path, methods, controller=nil)
50
+ add :site, path, controller || 'layout:render!', methods
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tzispa
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.5'
5
5
  FRAMEWORK_NAME = 'Tzispa'
6
6
  GEM_NAME = 'tzispa'
7
7
  end
data/lib/tzispa.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Tzispa
2
2
 
3
- require 'tzispa/app'
4
3
  require 'tzispa/version'
5
-
6
-
4
+ require 'tzispa/app'
5
+
7
6
  end
data/tzispa.gemspec CHANGED
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency 'rack', '~> 1.5'
19
19
  s.add_dependency 'puma', '~> 3.1'
20
- s.add_dependency 'i18n', '~> 0.7'
21
- s.add_dependency 'http_router', '~> 0.11'
22
- s.add_dependency 'moneta', '~> 0.8'
20
+ s.add_dependency 'i18n', '~> 0.7.0'
21
+ s.add_dependency 'http_router', '~> 0.11.2'
22
+ s.add_dependency 'moneta', '~> 0.8.0'
23
23
  s.add_dependency 'tzispa_helpers', '~> 0.1.0'
24
24
  s.add_dependency 'tzispa_utils', '~> 0.2.1'
25
25
  s.add_dependency 'tzispa_rig', '~> 0.2.7'
26
- s.add_dependency 'tzispa_data', '~> 0.1'
26
+ s.add_dependency 'tzispa_data', '~> 0.1.1'
27
27
 
28
28
  s.files = Dir.glob("{lib,bin}/**/*") + %w(README.md CHANGELOG.md LICENSE tzispa.gemspec)
29
29
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tzispa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Antonio Piñero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-21 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -44,42 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.7'
47
+ version: 0.7.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.7'
54
+ version: 0.7.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: http_router
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.11'
61
+ version: 0.11.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.11'
68
+ version: 0.11.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: moneta
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.8'
75
+ version: 0.8.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.8'
82
+ version: 0.8.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: tzispa_helpers
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0.1'
131
+ version: 0.1.1
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.1'
138
+ version: 0.1.1
139
139
  description: A sparkling web framework based on Rack and inspired by Sinatra and Lotus
140
140
  email:
141
141
  - japinero@area-integral.com
@@ -151,6 +151,7 @@ files:
151
151
  - lib/tzispa.rb
152
152
  - lib/tzispa/api/handler.rb
153
153
  - lib/tzispa/app.rb
154
+ - lib/tzispa/autoreload.rb
154
155
  - lib/tzispa/bin/tzispa
155
156
  - lib/tzispa/cli.rb
156
157
  - lib/tzispa/command/api.rb
@@ -160,7 +161,6 @@ files:
160
161
  - lib/tzispa/command/rig.rb
161
162
  - lib/tzispa/config/appconfig.rb
162
163
  - lib/tzispa/config/base.rb
163
- - lib/tzispa/config/routes.rb
164
164
  - lib/tzispa/config/yaml.rb
165
165
  - lib/tzispa/context.rb
166
166
  - lib/tzispa/controller/api.rb
@@ -174,6 +174,7 @@ files:
174
174
  - lib/tzispa/http/response.rb
175
175
  - lib/tzispa/http/session_flash_bag.rb
176
176
  - lib/tzispa/middleware.rb
177
+ - lib/tzispa/routes.rb
177
178
  - lib/tzispa/version.rb
178
179
  - tzispa.gemspec
179
180
  homepage: https://github.com/japiber/tzispa
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  version: '0'
197
198
  requirements: []
198
199
  rubyforge_project:
199
- rubygems_version: 2.4.8
200
+ rubygems_version: 2.5.1
200
201
  signing_key:
201
202
  specification_version: 4
202
203
  summary: A sparkling web framework
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
- require 'http_router'
5
- require 'tzispa/utils/string'
6
-
7
- module Tzispa
8
- module Config
9
- class Routes
10
-
11
- CONTROLLERS_BASE = 'Tzispa::Controller'
12
-
13
- attr_reader :router, :map_path
14
-
15
- def initialize(map_path=nil)
16
- @router = HttpRouter.new
17
- @map_path = map_path unless map_path=='/'
18
- end
19
-
20
- def path(path_id, params={})
21
- "#{@map_path}#{@router.path path_id, params}"
22
- end
23
-
24
- def add(route_id, path, controller, methods)
25
- spec_control, callmethod = controller.to_s.split(':')
26
- mpath = spec_control.split('#')
27
- controller = TzString.camelize(mpath.pop).to_s
28
- if mpath.count > 1
29
- controller_module = mpath.collect!{ |w| w.capitalize }.join('::')
30
- require_relative "./controller/#{controller.downcase}"
31
- else
32
- controller_module = CONTROLLERS_BASE
33
- require "tzispa/controller/#{controller.downcase}"
34
- end
35
- @router.add(path, {request_method: methods}).tap { |rule|
36
- rule.to TzString.constantize("#{controller_module}::#{controller}").new(callmethod)
37
- rule.name = route_id
38
- }
39
- end
40
-
41
- def index(path, methods, controller=nil)
42
- add :index, path, controller || 'layout:render!', methods
43
- end
44
-
45
- def api(path, methods, controller=nil)
46
- add :api, path, controller || 'api:dispatch!', methods
47
- end
48
-
49
- def site(path, methods, controller=nil)
50
- add :site, path, controller || 'layout:render!', methods
51
- end
52
-
53
- end
54
- end
55
- end