tzispa 0.4.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/tzispa/app.rb +1 -1
- data/lib/tzispa/cli.rb +0 -1
- data/lib/tzispa/command/api.rb +24 -0
- data/lib/tzispa/command/app.rb +19 -12
- data/lib/tzispa/command/cli/generate.rb +13 -4
- data/lib/tzispa/config/appconfig.rb +1 -0
- data/lib/tzispa/controller/api.rb +38 -9
- data/lib/tzispa/controller/base.rb +2 -2
- data/lib/tzispa/http/context.rb +4 -0
- data/lib/tzispa/version.rb +1 -1
- data/tzispa.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c4be6874602d23587c2ba452f1989d6fa49d358
|
4
|
+
data.tar.gz: a62b6ab378ef9cf8d4c33e5c34e5924d1ac882c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb163a5d484d121d42f7b9c3994453c9118df7d430a5bee41c748551a647e80786c1d7a0e7da29587c295e425605a83fae5a4e88dc3553fb2c1cde5ba97fc342
|
7
|
+
data.tar.gz: 4c4fb446ea60989923a78f49040b8389cc049ec9e4a4d2c6f60efc97778db4e051fb953d2e4b7f9010cb506ce9445f56e6a529c656a9fe4e02bce2ce54be006d
|
data/CHANGELOG.md
CHANGED
data/lib/tzispa/app.rb
CHANGED
@@ -76,7 +76,7 @@ module Tzispa
|
|
76
76
|
Mutex.new.synchronize {
|
77
77
|
@middleware.load!
|
78
78
|
@repository = Data::Repository.new(@config.repository.to_h).load! if @config.respond_to? :repository
|
79
|
-
@engine = Rig::Engine.new
|
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
82
|
I18n.load_path += Dir["#{@domain.path}/config/locales/*.yml"] if @config.respond_to?(:locales) && @config.locales.preload
|
data/lib/tzispa/cli.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'tzispa/controller/api'
|
2
|
+
|
3
|
+
module Tzispa
|
4
|
+
module Command
|
5
|
+
|
6
|
+
class Api
|
7
|
+
|
8
|
+
attr_reader :name, :domain
|
9
|
+
|
10
|
+
def initialize(name, app)
|
11
|
+
@prj = Project.open
|
12
|
+
raise "Application '#{app}' does not exists in project file" unless @prj.apps.include?(app)
|
13
|
+
@domain = Tzispa::Domain.new app
|
14
|
+
@name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate
|
18
|
+
Tzispa::Controller::Api.new.generate_handler(domain, name)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/tzispa/command/app.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'tzispa/domain'
|
3
3
|
require 'tzispa/utils/string'
|
4
|
+
require 'tzispa/utils/indenter'
|
4
5
|
require 'tzispa/config/appconfig'
|
5
6
|
require_relative 'project'
|
6
7
|
|
@@ -44,23 +45,29 @@ module Tzispa
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def create_class(mount_path=nil)
|
47
|
-
appclass = "#{TzString.camelize domain.name}App"
|
48
48
|
mount_path ||= DEFAULT_MOUNT_PATH
|
49
|
-
class_code = TzString.new
|
50
49
|
File.open("#{Project::START_FILE}","a") do |f|
|
51
|
-
f.puts
|
52
|
-
f.puts class_code.indenter("def initialize", 2)
|
53
|
-
f.puts class_code.indenter("super(:#{domain.name})", 2)
|
54
|
-
f.puts class_code.unindenter("end\n\n", 2)
|
55
|
-
f.puts class_code.unindenter("end\n\n", 2)
|
56
|
-
f.puts class_code.indenter("#{appclass}.mount '/#{mount_path}', self do |route|")
|
57
|
-
f.puts class_code.indenter("route.index '/', [:get, :head]", 2)
|
58
|
-
f.puts class_code.indenter("route.api '/__api_:sign/:handler/:verb(~:predicate)(/:sufix)', [:get, :head, :post]")
|
59
|
-
f.puts class_code.indenter("route.site '/:title(/@:id0)(@:id1)(@~:id2)(@@:id3)(@@~:id4)(@@@:id5)/:layout.:format', [:get, :head]")
|
60
|
-
f.puts class_code.unindenter("end\n\n", 2)
|
50
|
+
f.puts new_app_code(mount_path)
|
61
51
|
end
|
62
52
|
end
|
63
53
|
|
54
|
+
def new_app_code(mount_path)
|
55
|
+
appclass = "#{TzString.camelize domain.name}App"
|
56
|
+
Tzispa::Utils::Indenter.new(2).tap { |code|
|
57
|
+
code << "\nclass #{appclass} < Tzispa::Application\n\n"
|
58
|
+
code.indent << "def initialize\n"
|
59
|
+
code.indent << "super(:#{domain.name})\n"
|
60
|
+
code.unindent << "end\n\n"
|
61
|
+
code.unindent << "end\n\n"
|
62
|
+
code << "#{appclass}.mount '/#{mount_path}', self do |route|\n"
|
63
|
+
code.indent << "route.index '/', [:get, :head]\n"
|
64
|
+
code << "route.api '/__api_:sign/:handler/:verb(~:predicate)(/:sufix)', [:get, :head, :post]\n"
|
65
|
+
code << "route.site '/:title(/@:id0)(@:id1)(@~:id2)(@@:id3)(@@~:id4)(@@@:id5)/:layout.:format', [:get, :head]\n"
|
66
|
+
code.unindent << "end\n\n"
|
67
|
+
}.to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
|
64
71
|
def create_structure
|
65
72
|
unless File.exist? domain.path
|
66
73
|
Dir.mkdir "#{domain.path}"
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'thor'
|
2
|
-
|
3
|
-
require 'tzispa/command/app'
|
4
|
-
require 'tzispa/command/rig'
|
2
|
+
|
5
3
|
|
6
4
|
module Tzispa
|
7
5
|
module Command
|
@@ -9,12 +7,14 @@ module Tzispa
|
|
9
7
|
|
10
8
|
class Generate < Thor
|
11
9
|
|
10
|
+
require 'tzispa/command/project'
|
12
11
|
desc 'project', 'Generate Tzispa project components'
|
13
12
|
def project(name)
|
14
13
|
Tzispa::Command::Project.new(name).generate
|
15
14
|
puts "Project '#{name}' has been created"
|
16
15
|
end
|
17
16
|
|
17
|
+
require 'tzispa/command/app'
|
18
18
|
desc 'app', 'Generate new application into a project'
|
19
19
|
method_option :mount, :aliases => "-m", :desc => "The mount point for this app", :default => ""
|
20
20
|
method_option :host, :aliases => "-h", :desc => "The hostname used for this app ", :required => true
|
@@ -24,7 +24,7 @@ module Tzispa
|
|
24
24
|
puts "App '#{name}' has been created"
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
require 'tzispa/command/rig'
|
28
28
|
desc 'rig', 'Generate new rig template'
|
29
29
|
method_option :app, :aliases => "-a", :desc => "The app where the new template will be created", :required => true
|
30
30
|
method_option :type, :aliases => "-t", :desc => "The template type: block, static or layout ", :required => true
|
@@ -34,6 +34,15 @@ module Tzispa
|
|
34
34
|
puts "Rig #{options[:type]} template '#{name}' has been created in #{options[:app]}"
|
35
35
|
end
|
36
36
|
|
37
|
+
require 'tzispa/command/api'
|
38
|
+
desc 'api', 'Generate new api handler'
|
39
|
+
method_option :app, :aliases => "-a", :desc => "The app where the api handler will be created", :required => true
|
40
|
+
def api(name)
|
41
|
+
hnd = Tzispa::Command::Api.new(name, options[:app])
|
42
|
+
hnd.generate
|
43
|
+
puts "Api handler '#{name}' has been created in #{options[:app]}"
|
44
|
+
end
|
45
|
+
|
37
46
|
end
|
38
47
|
|
39
48
|
end
|
@@ -64,6 +64,44 @@ module Tzispa
|
|
64
64
|
send_file path, data
|
65
65
|
end
|
66
66
|
|
67
|
+
def generate_handler(domain, name)
|
68
|
+
@domain = domain
|
69
|
+
@handler = name
|
70
|
+
raise "The handler '#{name}' already exist" if File.exist?(handler_class_file)
|
71
|
+
File.open(handler_class_file, "w") { |f|
|
72
|
+
hnd_code = TzString.new
|
73
|
+
f.puts hnd_code.indenter("require 'tzispa/api/handler'\n\n")
|
74
|
+
level = 0
|
75
|
+
handler_namespace.split('::').each { |ns|
|
76
|
+
f.puts hnd_code.indenter("module #{ns}\n", level > 0 ? 2 : 0).to_s
|
77
|
+
level += 1
|
78
|
+
}
|
79
|
+
f.puts hnd_code.indenter("\nclass #{handler_class_name} < Tzispa::Api::Handler\n\n", 2)
|
80
|
+
f.puts hnd_code.indenter("end\n\n")
|
81
|
+
handler_namespace.split('::').each { |ns|
|
82
|
+
f.puts hnd_code.unindenter("end\n", 2)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def handler_class_name
|
88
|
+
"#{TzString.camelize @handler}Handler"
|
89
|
+
end
|
90
|
+
|
91
|
+
def handler_class_file
|
92
|
+
"#{@domain.path}/api/#{@handler}.rb"
|
93
|
+
end
|
94
|
+
|
95
|
+
def handler_namespace
|
96
|
+
"#{TzString.camelize @domain.name }::Api"
|
97
|
+
end
|
98
|
+
|
99
|
+
def handler_class
|
100
|
+
@domain.require "api/#{@handler}"
|
101
|
+
TzString.constantize "#{handler_namespace}::#{handler_class_name}"
|
102
|
+
end
|
103
|
+
|
104
|
+
|
67
105
|
private
|
68
106
|
|
69
107
|
attr_reader :hnd
|
@@ -82,15 +120,6 @@ module Tzispa
|
|
82
120
|
context.app.config.salt)
|
83
121
|
end
|
84
122
|
|
85
|
-
def handler_class_name
|
86
|
-
"#{TzString.camelize @domain.name }::Api::#{TzString.camelize @handler }Handler"
|
87
|
-
end
|
88
|
-
|
89
|
-
def handler_class
|
90
|
-
@domain.require "api/#{@handler.downcase}"
|
91
|
-
TzString.constantize handler_class_name
|
92
|
-
end
|
93
|
-
|
94
123
|
end
|
95
124
|
end
|
96
125
|
end
|
@@ -16,13 +16,13 @@ module Tzispa
|
|
16
16
|
attr_reader :context
|
17
17
|
def_delegators :@context, :request, :response, :config
|
18
18
|
|
19
|
-
def initialize(callmethod)
|
19
|
+
def initialize(callmethod=nil)
|
20
20
|
@callmethod = callmethod
|
21
21
|
end
|
22
22
|
|
23
23
|
def call(environment)
|
24
24
|
@context = Tzispa::Http::Context.new(environment)
|
25
|
-
invoke @callmethod
|
25
|
+
invoke @callmethod if @callmethod
|
26
26
|
response.finish
|
27
27
|
end
|
28
28
|
|
data/lib/tzispa/http/context.rb
CHANGED
@@ -66,6 +66,10 @@ module Tzispa
|
|
66
66
|
@app.class.routes.path path_id, params
|
67
67
|
end
|
68
68
|
|
69
|
+
def canonical_url(path_id, params={})
|
70
|
+
@app.config.canonical_url + path(path_id, params)
|
71
|
+
end
|
72
|
+
|
69
73
|
def api(handler, verb, predicate, sufix)
|
70
74
|
raise ArgumentError.new('missing parameter in api call') unless handler && verb
|
71
75
|
sign = sign_array [handler, verb, predicate], @app.config.salt
|
data/lib/tzispa/version.rb
CHANGED
data/tzispa.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency 'moneta', '~> 0.8'
|
23
23
|
s.add_dependency 'tzispa_helpers', '~> 0.1.0'
|
24
24
|
s.add_dependency 'tzispa_utils', '~> 0.2.1'
|
25
|
-
s.add_dependency 'tzispa_rig', '~> 0.2.
|
25
|
+
s.add_dependency 'tzispa_rig', '~> 0.2.7'
|
26
26
|
s.add_dependency 'tzispa_data', '~> 0.1'
|
27
27
|
|
28
28
|
s.files = Dir.glob("{lib,bin}/**/*") + %w(README.md CHANGELOG.md LICENSE tzispa.gemspec)
|
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
|
+
version: 0.4.1
|
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-
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.2.
|
117
|
+
version: 0.2.7
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.2.
|
124
|
+
version: 0.2.7
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: tzispa_data
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/tzispa/app.rb
|
154
154
|
- lib/tzispa/bin/tzispa
|
155
155
|
- lib/tzispa/cli.rb
|
156
|
+
- lib/tzispa/command/api.rb
|
156
157
|
- lib/tzispa/command/app.rb
|
157
158
|
- lib/tzispa/command/cli/generate.rb
|
158
159
|
- lib/tzispa/command/project.rb
|