tzispa 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c4be6874602d23587c2ba452f1989d6fa49d358
4
- data.tar.gz: a62b6ab378ef9cf8d4c33e5c34e5924d1ac882c4
3
+ metadata.gz: 1782a5ef50e95d6fd833efd6eacd2e29215e0ba5
4
+ data.tar.gz: b20ac80acf812c7a8c0479ebc7d23645829fddba
5
5
  SHA512:
6
- metadata.gz: eb163a5d484d121d42f7b9c3994453c9118df7d430a5bee41c748551a647e80786c1d7a0e7da29587c295e425605a83fae5a4e88dc3553fb2c1cde5ba97fc342
7
- data.tar.gz: 4c4fb446ea60989923a78f49040b8389cc049ec9e4a4d2c6f60efc97778db4e051fb953d2e4b7f9010cb506ce9445f56e6a529c656a9fe4e02bce2ce54be006d
6
+ metadata.gz: e5d2e25ffec6c8e87a6830edc5bafe4fc80d60e704b90f08c620a01e052c40a247c490420f434dab7470cbd187b3ec527bb5afd263ff5e79d70dac8136872e61
7
+ data.tar.gz: 93e818f963d31eaeec5f6d001940d1baf0b44f692989abd9c17d95f38e94674c90124e6fad315baa417086f28b44d747a134f85acbd38fa6c1e497d277118373
data/CHANGELOG.md CHANGED
@@ -2,8 +2,11 @@ Tzispa
2
2
 
3
3
  General purpose web framework
4
4
 
5
+ ## v0.4.2
6
+ - Preload api and helper modules an classes in app.load
7
+
5
8
  ## v0.4.1
6
- - Add support to generate canonical urls
9
+ - Add support to generate canonical urls
7
10
 
8
11
  ## v0.4.0
9
12
  - Added basic cli command engine
data/lib/tzispa/app.rb CHANGED
@@ -62,7 +62,6 @@ module Tzispa
62
62
  def initialize(domain_name)
63
63
  @domain = Domain.new(domain_name)
64
64
  @middleware = Middleware.new self
65
- I18n.load_path = Dir["config/locales/*.yml"]
66
65
  @config = Config::AppConfig.new(@domain).load!
67
66
  end
68
67
 
@@ -74,13 +73,14 @@ module Tzispa
74
73
  def load!
75
74
  unless @loaded
76
75
  Mutex.new.synchronize {
76
+ load_locales
77
77
  @middleware.load!
78
78
  @repository = Data::Repository.new(@config.repository.to_h).load! if @config.respond_to? :repository
79
79
  @engine = Rig::Engine.new(self, true, 32)
80
80
  @logger = Logger.new("logs/#{@domain.name}.log", 'weekly')
81
81
  @logger.level = @config.respond_to?(:developing) && @config.developing ? Logger::DEBUG : Logger::INFO
82
- I18n.load_path += Dir["#{@domain.path}/config/locales/*.yml"] if @config.respond_to?(:locales) && @config.locales.preload
83
- I18n.locale = @config.locales.default.to_sym if @config.respond_to?(:locales) && @config.locales.default
82
+ @domain.require_dir 'helpers'
83
+ @domain.require_dir 'api'
84
84
  @loaded = true
85
85
  }
86
86
  end
@@ -89,6 +89,13 @@ module Tzispa
89
89
 
90
90
  private
91
91
 
92
+ def load_locales
93
+ if @config.respond_to?(:locales)
94
+ I18n.load_path = Dir["config/locales/*.yml"]
95
+ I18n.load_path += Dir["#{@domain.path}/config/locales/*.yml"]
96
+ end
97
+ end
98
+
92
99
 
93
100
  end
94
101
  end
@@ -15,6 +15,7 @@ module Tzispa
15
15
  'config',
16
16
  'config/locales',
17
17
  'error',
18
+ 'helpers',
18
19
  'rig',
19
20
  'rig/block',
20
21
  'rig/layout',
@@ -37,6 +38,10 @@ module Tzispa
37
38
 
38
39
  private
39
40
 
41
+ def app_class_name
42
+ @app_class_name ||= "#{TzString.camelize domain.name}App"
43
+ end
44
+
40
45
  def update_project
41
46
  prj = Project.open
42
47
  raise "Application '#{domain.name}' already exist in this project" if prj.apps.include?(domain.name)
@@ -52,14 +57,13 @@ module Tzispa
52
57
  end
53
58
 
54
59
  def new_app_code(mount_path)
55
- appclass = "#{TzString.camelize domain.name}App"
56
60
  Tzispa::Utils::Indenter.new(2).tap { |code|
57
- code << "\nclass #{appclass} < Tzispa::Application\n\n"
61
+ code << "\nclass #{app_class_name} < Tzispa::Application\n\n"
58
62
  code.indent << "def initialize\n"
59
63
  code.indent << "super(:#{domain.name})\n"
60
64
  code.unindent << "end\n\n"
61
65
  code.unindent << "end\n\n"
62
- code << "#{appclass}.mount '/#{mount_path}', self do |route|\n"
66
+ code << "#{app_class_name}.mount '/#{mount_path}', self do |route|\n"
63
67
  code.indent << "route.index '/', [:get, :head]\n"
64
68
  code << "route.api '/__api_:sign/:handler/:verb(~:predicate)(/:sufix)', [:get, :head, :post]\n"
65
69
  code << "route.site '/:title(/@:id0)(@:id1)(@~:id2)(@@:id3)(@@~:id4)(@@@:id5)/:layout.:format', [:get, :head]\n"
@@ -53,6 +53,7 @@ module Tzispa
53
53
  cfg['sessions'] = Hash.new.tap { |ses|
54
54
  ses['enabled'] = true
55
55
  ses['timeout'] = 3600
56
+ ses['store_path'] = 'data/session'
56
57
  ses['secret'] = secret(32)
57
58
  }
58
59
  }
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'i18n'
2
3
 
3
4
  module Tzispa
4
5
 
@@ -13,6 +14,7 @@ module Tzispa
13
14
  @env = environment
14
15
  @app = environment[:tzispa__app]
15
16
  @repository = @app.repository.dup if @app.repository
17
+ I18n.locale = config.locales.default.to_sym if config.respond_to?(:locales)
16
18
  end
17
19
 
18
20
  end
@@ -30,7 +30,7 @@ module Tzispa
30
30
 
31
31
  def redirect
32
32
  context.flash << hnd.message
33
- url = hnd.data
33
+ url = hnd.data || request.referer
34
34
  context.redirect url, response
35
35
  end
36
36
 
data/lib/tzispa/domain.rb CHANGED
@@ -22,10 +22,24 @@ module Tzispa
22
22
  Kernel.require "./#{path}/#{file}"
23
23
  end
24
24
 
25
+ def require_dir(dir)
26
+ Dir["./#{path}/#{dir}/*.rb"].each { |file|
27
+ name = file.split('/').last.split('.').first
28
+ Kernel.require "./#{path}/#{dir}/#{name}"
29
+ }
30
+ end
31
+
25
32
  def load(file)
26
33
  Kernel.load "./#{path}/#{file}.rb"
27
34
  end
28
35
 
36
+ def load_dir(dir)
37
+ Dir["./#{path}/#{dir}/*.rb"].each { |file|
38
+ name = file.split('/').last
39
+ Kernel.load "./#{path}/#{dir}/#{name}"
40
+ }
41
+ end
42
+
29
43
  def self.require(domain, file)
30
44
  self.new(name: domain).require(file)
31
45
  end
@@ -28,6 +28,7 @@ module Tzispa
28
28
  super(environment)
29
29
  @request = Tzispa::Http::Request.new(environment)
30
30
  @response = Tzispa::Http::Response.new
31
+ session[:id] ||= SecureRandom.uuid if app.config.sessions.enabled
31
32
  end
32
33
 
33
34
  def router_params
@@ -63,17 +64,17 @@ module Tzispa
63
64
  end
64
65
 
65
66
  def path(path_id, params={})
66
- @app.class.routes.path path_id, params
67
+ app.class.routes.path path_id, params
67
68
  end
68
69
 
69
70
  def canonical_url(path_id, params={})
70
- @app.config.canonical_url + path(path_id, params)
71
+ app.config.canonical_url + path(path_id, params)
71
72
  end
72
73
 
73
74
  def api(handler, verb, predicate, sufix)
74
75
  raise ArgumentError.new('missing parameter in api call') unless handler && verb
75
- sign = sign_array [handler, verb, predicate], @app.config.salt
76
- @app.class.routes.path :api, {sign: sign, handler: handler, verb: verb, predicate: predicate, sufix: sufix}
76
+ sign = sign_array [handler, verb, predicate], app.config.salt
77
+ app.class.routes.path :api, {sign: sign, handler: handler, verb: verb, predicate: predicate, sufix: sufix}
77
78
  end
78
79
 
79
80
  end
@@ -57,8 +57,8 @@ module Tzispa
57
57
  def _load_session_middleware
58
58
  if @application.config.sessions.enabled
59
59
  use Rack::Session::Moneta,
60
- store: Moneta.new(:HashFile, dir: './data/session', expires: true, threadsafe: true),
61
- key: "_#{@application.config.id}__", ##{SecureRandom.hex(18)}
60
+ store: Moneta.new(:HashFile, dir: @application.config.sessions.store_path, expires: true, threadsafe: true),
61
+ key: "_#{@application.config.id}__",
62
62
  domain: @application.config.host_name,
63
63
  path: '/',
64
64
  expire_after: @application.config.sessions.timeout,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tzispa
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
  FRAMEWORK_NAME = 'Tzispa'
6
6
  GEM_NAME = 'tzispa'
7
7
  end
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.1
4
+ version: 0.4.2
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-05 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack