tzispa 0.4.0 → 0.4.1

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: cd74c98b9c732e76ab7fa87e760664c4bb1770db
4
- data.tar.gz: 0c805105cfede7ef61edced4d066e510db90000a
3
+ metadata.gz: 5c4be6874602d23587c2ba452f1989d6fa49d358
4
+ data.tar.gz: a62b6ab378ef9cf8d4c33e5c34e5924d1ac882c4
5
5
  SHA512:
6
- metadata.gz: 36d1a0becbad7b32e90cce228d2ff4a6c291ba02cc3390af297ec98de4aeb8b75249836425b1a275eb1d9dfa6ae66dc6e8e028c0a73344b3f95a361dce4085d7
7
- data.tar.gz: ffa0c807d47a7f36e038d4cc757e1c9f422c0f87a0833f00b454683f4af10d5daa770089e150e85258a3aab6e6a60366b9dd5a390b3b94cd79924d6c7f4851ba
6
+ metadata.gz: eb163a5d484d121d42f7b9c3994453c9118df7d430a5bee41c748551a647e80786c1d7a0e7da29587c295e425605a83fae5a4e88dc3553fb2c1cde5ba97fc342
7
+ data.tar.gz: 4c4fb446ea60989923a78f49040b8389cc049ec9e4a4d2c6f60efc97778db4e051fb953d2e4b7f9010cb506ce9445f56e6a529c656a9fe4e02bce2ce54be006d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@ Tzispa
2
2
 
3
3
  General purpose web framework
4
4
 
5
+ ## v0.4.1
6
+ - Add support to generate canonical urls
7
+
5
8
  ## v0.4.0
6
9
  - Added basic cli command engine
7
10
  - Added some documentation in README.md
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 self
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
@@ -13,7 +13,6 @@ module Tzispa
13
13
  require 'tzispa/command/cli/generate'
14
14
  register Tzispa::Command::Cli::Generate, 'generate', 'generate [SUBCOMMAND]', 'Generate Tzispa components'
15
15
 
16
-
17
16
  end
18
17
 
19
18
  end
@@ -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
@@ -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 class_code.indenter("\nclass #{appclass} < Tzispa::Application\n\n")
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
- require 'tzispa/command/project'
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
@@ -41,6 +41,7 @@ module Tzispa
41
41
  cfg['default_layout'] = layout
42
42
  cfg['default_format'] = 'htm'
43
43
  cfg['host_name'] = host
44
+ cfg['canonical_url'] = "http://#{host}"
44
45
  cfg['dev_mode'] = dev_mode
45
46
  cfg['default_encoding'] = 'utf-8'
46
47
  cfg['auth_required'] = false
@@ -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
 
@@ -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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tzispa
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  FRAMEWORK_NAME = 'Tzispa'
6
6
  GEM_NAME = 'tzispa'
7
7
  end
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.0'
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.0
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-03-27 00:00:00.000000000 Z
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.0
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.0
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