spiderfw 0.5.7 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/Rakefile +17 -6
  2. data/apps/cas_server/controllers/mixins/cas_login_mixin.rb +18 -5
  3. data/apps/cas_server/lib/cas.rb +1 -1
  4. data/apps/cms/models/content.rb +16 -0
  5. data/apps/cms/models/news_item.rb +7 -0
  6. data/apps/cms/models/translation.rb +14 -0
  7. data/apps/cms/views/admin/admin.shtml +16 -0
  8. data/apps/cms/views/admin/content.shtml +4 -0
  9. data/apps/core/acl/_init.rb +10 -0
  10. data/apps/core/acl/controllers/acl_controller.rb +14 -0
  11. data/apps/core/acl/models/permission.rb +11 -0
  12. data/apps/core/acl/views/acl.layout.shtml +8 -0
  13. data/apps/core/acl/views/index.shtml +3 -0
  14. data/apps/core/auth/controllers/mixins/auth_helper.rb +3 -3
  15. data/apps/core/auth/lib/authenticable.rb +4 -0
  16. data/apps/core/auth/models/super_user.rb +1 -0
  17. data/apps/core/auth/po/it/spider_auth.po +18 -10
  18. data/apps/core/auth/po/spider_auth.pot +13 -1
  19. data/apps/core/components/_init.rb +2 -1
  20. data/apps/core/components/po/it/spider_components.po +3 -3
  21. data/apps/core/components/po/spider_components.pot +3 -3
  22. data/apps/core/components/public/css/month_calendar.css +24 -0
  23. data/apps/core/components/public/js/jquery/jquery-1.4.2-min.js +154 -0
  24. data/apps/core/components/public/js/jquery/jquery-1.4.2.js +6240 -0
  25. data/apps/core/components/public/js/jquery/plugins/jquery.form.js +1 -1
  26. data/apps/core/components/public/js/spider.js +26 -20
  27. data/apps/core/components/widgets/admin/admin.rb +1 -1
  28. data/apps/core/components/widgets/crud/crud.rb +1 -1
  29. data/apps/core/components/widgets/list/list.rb +2 -2
  30. data/apps/core/components/widgets/month_calendar/month_calendar.rb +67 -0
  31. data/apps/core/components/widgets/month_calendar/month_calendar.shtml +21 -0
  32. data/apps/core/components/widgets/table/table.rb +4 -2
  33. data/apps/core/components/widgets/table/table.shtml +37 -31
  34. data/apps/core/forms/_init.rb +2 -1
  35. data/apps/core/forms/po/it/spider_forms.po +14 -2
  36. data/apps/core/forms/po/spider_forms.pot +13 -1
  37. data/apps/core/forms/public/css/file_input.css +15 -0
  38. data/apps/core/forms/public/{form.css → css/form.css} +8 -0
  39. data/apps/core/forms/public/file_input.js +37 -0
  40. data/apps/core/forms/tags/element_label.erb +4 -1
  41. data/apps/core/forms/tags/element_row.erb +7 -2
  42. data/apps/core/forms/tags/row.erb +10 -1
  43. data/apps/core/forms/widgets/form/form.rb +43 -10
  44. data/apps/core/forms/widgets/form/form.shtml +12 -5
  45. data/apps/core/forms/widgets/inputs/date_time/date_time.shtml +1 -0
  46. data/apps/core/forms/widgets/inputs/file_input/file_input.rb +43 -0
  47. data/apps/core/forms/widgets/inputs/file_input/file_input.shtml +12 -0
  48. data/apps/core/forms/widgets/inputs/input/input.rb +23 -1
  49. data/apps/core/forms/widgets/inputs/password/password.rb +1 -0
  50. data/apps/core/forms/widgets/inputs/text/text.shtml +1 -1
  51. data/apps/core/forms/widgets/inputs/text_area/text_area.shtml +2 -2
  52. data/apps/git_model_versioning/models/mixins/git_versioned.rb +91 -0
  53. data/apps/hippo/models/mixins/hippo_struct.rb +42 -26
  54. data/apps/master/controllers/git.rb +32 -0
  55. data/apps/messenger/_init.rb +1 -1
  56. data/apps/messenger/config/options.rb +2 -0
  57. data/apps/messenger/config/worker/queue.rb +3 -0
  58. data/apps/messenger/controllers/mixins/{messenger_controller_mixin.rb → messenger_helper.rb} +8 -6
  59. data/apps/messenger/messenger.rb +10 -3
  60. data/apps/messenger/models/message.rb +2 -2
  61. data/apps/messenger/po/it/spider_messenger.po +1 -1
  62. data/apps/messenger/po/spider_messenger.pot +1 -1
  63. data/apps/saml/_init.rb +13 -0
  64. data/apps/saml/controllers/saml2idp.rb +18 -0
  65. data/apps/saml/lib/bindings/http_redirect_binding.rb +14 -0
  66. data/apps/saml/lib/messages/authn_request.rb +52 -0
  67. data/apps/saml/lib/saml.rb +10 -0
  68. data/apps/soap/controllers/soap_controller.rb +12 -2
  69. data/apps/soap/lib/soap.rb +16 -1
  70. data/apps/soap/soap.gemspec +10 -0
  71. data/apps/webdav/lib/locking.rb +2 -2
  72. data/apps/worker/_init.rb +2 -0
  73. data/apps/worker/config/options.rb +1 -0
  74. data/apps/worker/worker.rb +17 -4
  75. data/blueprints/app/__APP__.appspec +4 -0
  76. data/blueprints/app/_init.rb +5 -8
  77. data/blueprints/app/controllers/__APP___controller.rb +2 -1
  78. data/blueprints/app/views/__APP__.layout.shtml +4 -1
  79. data/blueprints/install/config/config.yml +2 -4
  80. data/blueprints/model.rb +15 -0
  81. data/data/locale/it/LC_MESSAGES/spider.mo +0 -0
  82. data/data/locale/it/LC_MESSAGES/spider_auth.mo +0 -0
  83. data/data/locale/it/LC_MESSAGES/spider_components.mo +0 -0
  84. data/data/locale/it/LC_MESSAGES/spider_forms.mo +0 -0
  85. data/data/locale/it/LC_MESSAGES/spider_messenger.mo +0 -0
  86. data/lib/spiderfw/app.rb +93 -31
  87. data/lib/spiderfw/autoload.rb +1 -0
  88. data/lib/spiderfw/cmd/cmd.rb +8 -1
  89. data/lib/spiderfw/cmd/commands/config.rb +54 -0
  90. data/lib/spiderfw/config/configuration.rb +30 -0
  91. data/lib/spiderfw/config/options/spider.rb +18 -6
  92. data/lib/spiderfw/controller/controller.rb +12 -11
  93. data/lib/spiderfw/controller/dispatcher.rb +5 -4
  94. data/lib/spiderfw/controller/http_controller.rb +16 -2
  95. data/lib/spiderfw/controller/mixins/http_mixin.rb +3 -2
  96. data/lib/spiderfw/controller/mixins/static_content.rb +8 -2
  97. data/lib/spiderfw/controller/mixins/visual.rb +72 -52
  98. data/lib/spiderfw/controller/request.rb +7 -3
  99. data/lib/spiderfw/controller/scene.rb +6 -0
  100. data/lib/spiderfw/controller/session.rb +12 -8
  101. data/lib/spiderfw/env.rb +1 -1
  102. data/lib/spiderfw/http/adapters/mongrel.rb +1 -1
  103. data/lib/spiderfw/http/http.rb +48 -19
  104. data/lib/spiderfw/i18n/cldr.rb +53 -3
  105. data/lib/spiderfw/i18n/i18n.rb +52 -2
  106. data/lib/spiderfw/i18n/provider.rb +24 -0
  107. data/lib/spiderfw/i18n/rails.rb +24 -0
  108. data/lib/spiderfw/model/active_record.rb +3 -3
  109. data/lib/spiderfw/model/base_model.rb +45 -14
  110. data/lib/spiderfw/model/condition.rb +11 -2
  111. data/lib/spiderfw/model/data_type.rb +15 -7
  112. data/lib/spiderfw/model/datatypes/decimal.rb +15 -3
  113. data/lib/spiderfw/model/datatypes/file_path.rb +50 -0
  114. data/lib/spiderfw/model/datatypes/serialized_object.rb +0 -4
  115. data/lib/spiderfw/model/datatypes/uuid.rb +3 -3
  116. data/lib/spiderfw/model/datatypes.rb +1 -0
  117. data/lib/spiderfw/model/extended_models/managed.rb +11 -2
  118. data/lib/spiderfw/model/mappers/db_mapper.rb +116 -52
  119. data/lib/spiderfw/model/mappers/mapper.rb +36 -14
  120. data/lib/spiderfw/model/mixins/state_machine.rb +45 -9
  121. data/lib/spiderfw/model/mixins/versioned.rb +1 -1
  122. data/lib/spiderfw/model/model.rb +2 -1
  123. data/lib/spiderfw/model/query_set.rb +21 -3
  124. data/lib/spiderfw/model/request.rb +7 -0
  125. data/lib/spiderfw/model/storage/db/adapters/mssql.rb +2 -1
  126. data/lib/spiderfw/model/storage/db/adapters/mysql.rb +4 -1
  127. data/lib/spiderfw/model/storage/db/adapters/oci8.rb +35 -18
  128. data/lib/spiderfw/model/storage/db/adapters/sqlite.rb +68 -34
  129. data/lib/spiderfw/model/storage/db/connectors/odbc.rb +1 -1
  130. data/lib/spiderfw/model/storage/db/db_schema.rb +33 -4
  131. data/lib/spiderfw/model/storage/db/db_storage.rb +27 -8
  132. data/lib/spiderfw/requires.rb +2 -0
  133. data/lib/spiderfw/tag/tag.rb +1 -1
  134. data/lib/spiderfw/templates/blocks/attr_if.rb +7 -1
  135. data/lib/spiderfw/templates/blocks/each.rb +8 -3
  136. data/lib/spiderfw/templates/blocks/html.rb +12 -22
  137. data/lib/spiderfw/templates/blocks/render.rb +3 -3
  138. data/lib/spiderfw/templates/blocks/run.rb +47 -11
  139. data/lib/spiderfw/templates/blocks/tag_if.rb +2 -2
  140. data/lib/spiderfw/templates/blocks/text.rb +2 -1
  141. data/lib/spiderfw/templates/blocks/widget.rb +5 -3
  142. data/lib/spiderfw/templates/blocks/yield.rb +1 -1
  143. data/lib/spiderfw/templates/template.rb +27 -24
  144. data/lib/spiderfw/templates/template_blocks.rb +37 -14
  145. data/lib/spiderfw/utils/monkey/exception.rb +1 -1
  146. data/lib/spiderfw/utils/monkey/nil_class.rb +7 -0
  147. data/lib/spiderfw/utils/monkey/numeric.rb +15 -0
  148. data/lib/spiderfw/version.rb +1 -1
  149. data/lib/spiderfw/widget/widget.rb +36 -33
  150. data/lib/spiderfw/widget/widget_attributes.rb +1 -1
  151. data/lib/spiderfw.rb +18 -5
  152. data/spider.gemspec +5 -5
  153. metadata +44 -18
  154. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.1.0.js +0 -187
  155. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.1.0.min.js +0 -1
  156. data/apps/core/components/public/js/jquery/plugins/jtree/jquery.jtree.spider.1.0.js +0 -193
  157. data/apps/core/forms/widgets/inputs/subform/subform.rb +0 -10
  158. data/apps/core/forms/widgets/inputs/subform/subform.shtml +0 -5
  159. data/apps/messenger/config/worker.rb +0 -3
  160. data/lib/spiderfw/controller/app_controller.rb +0 -14
  161. data/lib/spiderfw/utils/test_case.rb +0 -24
@@ -0,0 +1,52 @@
1
+ require 'base64'
2
+ require 'stringio'
3
+ require 'zlib'
4
+
5
+ module Spider; module SAML
6
+
7
+ class AuthnRequest
8
+
9
+ def initialize(xml_string=nil)
10
+ @version = '2.0'
11
+ parse_xml(xml_string) if (xml_string)
12
+ end
13
+
14
+ def parse_xml(xml_string)
15
+ xml = Nokogiri::XML(xml_string)
16
+ @force_authn = xml.root['ForceAuthn'] == 'true'
17
+ @assertion_consumer_service_url = xml.root['AssertionConsumerServiceURL']
18
+ @attribute_consuming_service_index = xml.root['AttributeConsumingServiceIndex']
19
+ @provider_name = xml.root['ProviderName']
20
+ @id = xml.root['ID']
21
+ @version = xml.root['Version']
22
+ @issue_instant = DateTime.strptime(xml['IssueInstant'], '%Y-%m-%dT%H:%M:%S%Z')
23
+ @destination = xml.root['Destination']
24
+ @consent = xml.root['Consent']
25
+ issuer = xml.xpath('//issuer')
26
+ @issuer = issuer[0].content if issuer[0]
27
+ end
28
+
29
+ def to_xml
30
+ xml = ''
31
+ xm = Builder::XmlMarkup.new(:target => xml, :indent => 2)
32
+ xm.samlp(:AuthnRequest,
33
+ 'xmlns:samlp' => SAML::SAMLPNs,
34
+ 'xmlns:saml' => SAML::SAMLNs,
35
+ 'ID' => @id,
36
+ 'Version' => @version,
37
+ 'IssueInstant' => @issue_instant.strftime('%Y-%m-%dT%H:%M:%S%Z'),
38
+ 'ForceAuthn' => @force_authn,
39
+ 'IsPassive' => @is_passive,
40
+ 'Destination' => @destination,
41
+ 'Consent' => @consent
42
+ ) do
43
+ xm.saml(:Issuer, @issuer)
44
+ end
45
+ end
46
+
47
+
48
+
49
+ end
50
+
51
+
52
+ end; end
@@ -0,0 +1,10 @@
1
+ module Spider;
2
+
3
+ module Saml
4
+
5
+ SAMLPNs = 'urn:oasis:names:tc:SAML:2.0:protocol'
6
+ SAMLNs = 'urn:oasis:names:tc:SAML:2.0:assertion'
7
+
8
+ end
9
+
10
+ end
@@ -122,6 +122,11 @@ module Spider
122
122
  end
123
123
 
124
124
  def before(action='', *params)
125
+ begin
126
+ # Debugger post mortem interferes with the mapping of exceptions
127
+ Debugger.post_mortem = false
128
+ rescue NameError, RuntimeError
129
+ end
125
130
  method = @request.env['REQUEST_METHOD']
126
131
  @soap_proxy = SoapProxy.new(self, self.class.soap_methods)
127
132
  @soap_registry = SOAP::Mapping::Registry.new
@@ -129,6 +134,9 @@ module Spider
129
134
  t.soap_controller = self.class
130
135
  @soap_registry.add(t, t.soap_class, t.soap_factory, t.soap_info)
131
136
  end
137
+ unless Spider.runmode == 'devel'
138
+ @soap_registry.add(RuntimeError, SOAP::Mapping::SOAPException, CustomExceptionFactory.new, nil)
139
+ end
132
140
  if method == 'POST'
133
141
  @router = ::SOAP::RPC::Router.new(self.class.name)
134
142
  @router.mapping_registry = @soap_registry
@@ -262,11 +270,13 @@ module Spider
262
270
 
263
271
 
264
272
  # Service
265
-
273
+
274
+ soap_address = request_url
275
+ soap_address += '/' unless soap_address[-1].chr == '/'
266
276
  xm.service('name' => self.class.soap_service_name) do
267
277
  xm.port('name' => self.class.soap_port_name, 'binding' => 'typens:'+self.class.soap_binding_name) do
268
278
  xm.soap(:address,
269
- 'location' => request_url)
279
+ 'location' => soap_address)
270
280
  end
271
281
  end
272
282
 
@@ -23,7 +23,7 @@ module SOAP; module Mapping
23
23
  end
24
24
 
25
25
  end; end
26
-
26
+
27
27
  module Spider
28
28
 
29
29
  module Soap
@@ -78,6 +78,21 @@ module Spider
78
78
  end
79
79
  end
80
80
 
81
+ class CustomExceptionFactory < SOAP::Mapping::Factory
82
+
83
+ def obj2soap(soap_class, obj, info, map)
84
+ soap_obj = ::SOAP::SOAPStruct.new
85
+ elename = ::SOAP::Mapping.name2elename("message")
86
+ soap_obj.add elename, ::SOAP::Mapping._obj2soap(obj.message, map)
87
+ soap_obj
88
+ end
89
+
90
+ def soap2obj(obj_class, node, info, map)
91
+ return RuntimeError.new(node['message'].data)
92
+ end
93
+
94
+ end
95
+
81
96
  module SoapType
82
97
  def self.included(klass)
83
98
  klass.extend(ClassMethods)
@@ -0,0 +1,10 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "Soap"
3
+ s.version = "0.4.1"
4
+ s.date = "2009-06-15"
5
+ s.authors = ["Ivan Pirlik"]
6
+ s.email = %q{ivan.pirlik@gmail.com}
7
+ s.summary = %q{Soap controller}
8
+ s.description = %q{Soap Controller}
9
+ s.files = [ "README", "Changelog", "LICENSE", "demo.rb", "demo.conf", "lib/parseconfig.rb"]
10
+ end
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'uuid'
2
+ require 'uuidtools'
3
3
  require 'spiderfw/utils/shared_store'
4
4
 
5
5
  module Locking
@@ -17,7 +17,7 @@ module Locking
17
17
  @properties = properties
18
18
  @created = Time.now
19
19
 
20
- @token = UUID.new.generate
20
+ @token = UUIDTools::UUID.random_create.to_s
21
21
  end
22
22
 
23
23
  def [](key)
data/apps/worker/_init.rb CHANGED
@@ -11,3 +11,5 @@ module Spider
11
11
 
12
12
  end
13
13
 
14
+
15
+ Spider.register_resource_type :worker, :path => 'config/worker', :extensions => ['rb']
@@ -1,5 +1,6 @@
1
1
  module Spider
2
2
 
3
+ config_option 'worker.enable', :type => Spider::DataTypes::Bool, :default => lambda{ Spider.config.get('runmode') == 'devel' ? false : true }
3
4
  config_option 'worker.fork', :type => Spider::DataTypes::Bool, :default => lambda{
4
5
  RUBY_PLATFORM =~ /win32|mingw32/ ? false : true
5
6
  }
@@ -29,10 +29,12 @@ module Spider
29
29
  end
30
30
 
31
31
  def self.app_startup
32
+ return unless Spider.conf.get('worker.enable')
32
33
  @runner = start_runner unless running?
33
34
  end
34
35
 
35
36
  def self.app_shutdown
37
+ return unless Spider.conf.get('worker.enable')
36
38
  @mutex.try_lock || return
37
39
  Spider::Logger.info("Shutting down worker in #{Process.pid}")
38
40
  if @runner
@@ -78,9 +80,18 @@ module Spider
78
80
  load @scripts_dir+'/'+script
79
81
  end
80
82
  end
81
- # every(Spider.conf.get('worker.jobs_interval').to_s+'s') do
82
- # self.run_jobs
83
- # end
83
+ Spider.apps.each do |name, mod|
84
+ if File.directory?(mod.path+'/config/worker')
85
+ Dir.glob(mod.path+'/config/worker/*.rb').each do |path|
86
+ file = File.basename(path, '.rb')
87
+ next if file[0].chr == '.'
88
+ res = Spider.find_resource(:worker, file, nil, mod)
89
+ if res
90
+ load res.path
91
+ end
92
+ end
93
+ end
94
+ end
84
95
  @mutex.unlock
85
96
  end
86
97
  end
@@ -108,6 +119,8 @@ module Spider
108
119
  begin
109
120
  Process::kill 0, pid
110
121
  return pid
122
+ rescue Errno::EPERM
123
+ return pid
111
124
  rescue Errno::ESRCH
112
125
  File.unlink(pid_file)
113
126
  return false
@@ -165,4 +178,4 @@ module Spider
165
178
  end
166
179
 
167
180
 
168
- end
181
+ end
@@ -0,0 +1,4 @@
1
+ id "<%= app_name %>"
2
+ name "<%= app_name.split('_').map{|part| part.capitalize }.join(' ') %>"
3
+ version "0.1"
4
+ author ""
@@ -1,10 +1,7 @@
1
- require 'apps/<%= app_path %>/controllers/<%= app_name %>_controller.rb'<% tab = (modules.length > 1) ? " " : "" %><%= "\n" if (modules.length > 1) %>
2
- <%= modules[0..-2].inject(""){ |s, mod| s+= "; " if (s.length > 0); s+="module #{mod}"}+"\n" if (modules.length > 1)%>
3
- <%=tab%>module <%=modules[-1]%>
4
- <%=tab%> @description = ""
5
- <%=tab%> @version = 0.1
6
- <%=tab%> @path = File.dirname(__FILE__)
7
- <%=tab%> @controller = :<%= module_name %>Controller
1
+ <%= modules[0..-2].inject(""){ |s, mod| s+= "; " if (s.length > 0); s+="module #{mod}"}+"\n" if (modules.length > 1)%><%= "\n" if (modules.length > 1) %><% tab = (modules.length > 1) ? " " : ""
2
+ %><%=tab%>module <%=modules[-1]%>
8
3
  <%=tab%> include Spider::App
4
+ <%=tab%> @controller = :<%= module_name %>Controller
9
5
  <%=tab%>end
10
- <%= "\n"+modules[0..-2].inject(""){ |s, mod| s+= "; " if (s.length > 0); s+="end" if (modules.length > 1)} %>
6
+ <%= "\n"+modules[0..-2].inject(""){ |s, mod| s+= "; " if (s.length > 0); s+="end" if (modules.length > 1)}
7
+ %>require 'apps/<%= app_path %>/controllers/<%= app_name %>_controller'
@@ -1,9 +1,10 @@
1
1
  <%= modules[0..-2].inject(""){ |s, mod| s+= "module #{mod}; "} %>module <%=modules[-1]%>
2
2
 
3
- class <%= module_name %>Controller < Spider::AppController
3
+ class <%= module_name %>Controller < Spider::PageController
4
4
 
5
5
  layout '<%= app_name %>'
6
6
 
7
+ __.html
7
8
  def index
8
9
  @scene.msg = 'Hello!'
9
10
  render('index')
@@ -1,5 +1,8 @@
1
1
  <html>
2
- <head></head>
2
+ <head>
3
+ <script sp:each='@assets[:js] |script|' type="text/javascript" src="{ script }"></script>
4
+ <link sp:each='@assets[:css] |css_file|' rel='stylesheet' href='{ css_file }' />
5
+ </head>
3
6
  <body>
4
7
  <div id="content">
5
8
  <sp:yield />
@@ -1,14 +1,12 @@
1
1
  runmode: 'devel'
2
- template.cache.disable: true
3
- client.text_editor: 'textmate'
4
- locale: 'it'
5
2
  session.store: 'file'
3
+ client.text_editor: 'textmate'
6
4
 
7
- #set devel:
8
5
  storages:
9
6
  default:
10
7
  url: 'db:sqlite://var/db.sqlite'
11
8
 
12
9
  set devel:
10
+ template.cache.disable: true
13
11
  debugger.start: true
14
12
  debug.console.level: DEBUG
@@ -0,0 +1,15 @@
1
+ <%= modules[0..-2].inject(""){ |s, mod| s+= "module #{mod}; "} %>module <%=modules[-1]%>
2
+
3
+ class <%= model.name %> < Spider::Model::BaseModel
4
+
5
+ layout '<%= app_name %>.layout'
6
+
7
+ def index
8
+ @scene.msg = 'Hello!'
9
+ render('index')
10
+ end
11
+
12
+ end
13
+
14
+
15
+ <%= modules[0..-2].inject("") { |str, mod| str+= 'end; '} %>end
Binary file
data/lib/spiderfw/app.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'spiderfw/controller/app_controller'
2
1
  require 'fileutils'
3
2
 
4
3
  module Spider
@@ -10,14 +9,19 @@ module Spider
10
9
 
11
10
  include Spider::DataTypes
12
11
 
13
- #@controller ||= :"Spider::AppController"
14
12
  class << self
15
- attr_reader :path, :pub_path, :test_path, :setup_path, :widgets_path, :views_path, :tags_path, :models_path
13
+ attr_reader :id, :path, :pub_path, :test_path, :setup_path, :widgets_path, :views_path, :tags_path, :models_path
16
14
  attr_reader :short_name, :route_url, :label, :version
17
- attr_reader :short_prefix
15
+ attr_accessor :short_prefix
18
16
  attr_reader :command
17
+ attr_reader :spec
19
18
 
20
19
  def init
20
+ unless @path
21
+ file = caller[1].split(':')[0]
22
+ dir = File.expand_path(File.dirname(file))
23
+ @path = dir
24
+ end
21
25
  @short_name ||= Inflector.underscore(self.name).gsub('/', '_')
22
26
  @pub_path ||= @path+'/public'
23
27
  @test_path ||= @path+'/test'
@@ -26,15 +30,19 @@ module Spider
26
30
  @widgets_path ||= @path+'/widgets'
27
31
  @views_path ||= @path+'/views'
28
32
  @tags_path ||= @path+'/tags'
33
+ @version = Gem::Version.new(@version.to_s) if @version && !@version.is_a?(Gem::Version)
34
+ spec_path = "#{@path}/#{@short_name}.appspec"
35
+ load_spec(spec_path) if File.exists?(spec_path)
29
36
  @route_url ||= Inflector.underscore(self.name)
30
37
  @label ||= @short_name.split('_').each{ |p| p[0] = p[0].chr.upcase }.join(' ')
31
- @version = Gem::Version.new(@version.to_s) unless @version.is_a?(Gem::Version)
38
+
32
39
  find_tags
33
40
  end
34
41
 
35
42
  def request_url
36
43
  Spider::ControllerMixins::HTTPMixin.reverse_proxy_mapping('/'+@route_url)
37
44
  end
45
+ alias :url :request_url
38
46
 
39
47
  def pub_url
40
48
  request_url+'/public'
@@ -44,7 +52,7 @@ module Spider
44
52
  #controllers = self.const_get(:Controllers)
45
53
  if (!@controller || !const_defined?(@controller))
46
54
  @controller = :AppController
47
- return const_set(@controller, Spider::AppController.clone)
55
+ return const_set(@controller, Spider::PageController.clone)
48
56
 
49
57
  end
50
58
  return const_get(@controller)
@@ -117,7 +125,7 @@ module Spider
117
125
  name = File.basename(entry, '.erb')
118
126
  klass = Spider::Tag.new_class(@tags_path+'/'+entry)
119
127
  const_set(Spider::Inflector.camelize(name).to_sym, klass)
120
- Spider::Logger.debug("REGISTERED TAG #{name}, #{klass}")
128
+ #Spider::Logger.debug("REGISTERED TAG #{name}, #{klass}")
121
129
  register_tag(name, klass)
122
130
  end
123
131
  end
@@ -150,37 +158,91 @@ module Spider
150
158
  end
151
159
  end
152
160
 
161
+ def load_spec(spec_path=nil)
162
+ @spec = AppSpec.load(spec_path)
163
+ @spec.app_id = File.basename(spec_path, 'appsec') unless @spec.app_id
164
+ @version = @spec.version if @spec.version
165
+ end
166
+
153
167
 
154
168
  end
155
-
156
- # controllers = Spider::App::Controllers.clone
157
- # controllers.app = mod
158
- # Spider.logger.debug("Controllers.app")
159
- # Spider.logger.debug(controllers.to_s)
160
- # Spider.logger.debug(controllers.app)
161
- #
162
- # mod.const_set(:Controllers, controllers) unless mod.const_defined?(:Controllers)
163
- # Spider.logger.debug(Controllers)
169
+
164
170
  end
165
171
  mod.init()
166
- # routes_file = "#{mod.path}/routes.rb"
167
- # if (File.exist?(routes_file))
168
- # load(routes_file)
169
- # else
170
- # mod.controller.route('/', mod.name+'::MainController')
171
- # end
172
172
  Spider::add_app(mod)
173
173
  end
174
174
 
175
- # module Controllers
176
- # def self.app=(app)
177
- # @app = app
178
- # end
179
- # def self.app
180
- # @app
181
- # end
182
- #
183
- # end
175
+ class AppSpec
176
+ @@attributes = []
177
+
178
+ def self.attribute(name)
179
+ @@attributes << name
180
+ str = <<END_OF_EVAL
181
+ def #{name}(val=nil)
182
+ @#{name} = val if val
183
+ @#{name}
184
+ end
185
+ END_OF_EVAL
186
+ class_eval(str)
187
+ end
188
+
189
+ attribute :app_id
190
+ attribute :name
191
+ attribute :description
192
+ attribute :authors
193
+ attribute :git_repo
194
+ attribute :git_repo_ro
195
+ attribute :git_repo_rw
196
+ attribute :depends
197
+ attribute :gems
198
+ attribute :version
199
+
200
+ def id(val=nil)
201
+ self.app_id(val)
202
+ end
203
+
204
+ def version(val=nil)
205
+ @version = Gem::Version.new(val) if val
206
+ @version
207
+ end
208
+
209
+ def author(val = nil)
210
+ @authors = [val] if val
211
+ @authors ||= []
212
+ @authors[0]
213
+ end
214
+
215
+ def load(spec_path)
216
+ self.eval(File.read(spec_path), spec_path)
217
+ self
218
+ end
219
+
220
+ def self.load(spec_path)
221
+ self.new.load(spec_path)
222
+ end
223
+
224
+ def eval(text, path=nil)
225
+ self.instance_eval(text)
226
+ self
227
+ end
228
+
229
+ def self.eval(text, path=nil)
230
+ self.new.eval(text, path)
231
+ end
232
+
233
+ def to_h
234
+ h = {}
235
+ @@attributes.each do |a|
236
+ h[a] = send(a)
237
+ end
238
+ h
239
+ end
240
+
241
+ def to_json
242
+ to_h.to_json
243
+ end
244
+
245
+ end
184
246
 
185
247
  end
186
248
 
@@ -2,6 +2,7 @@ module Spider
2
2
  autoload :Logger, "spiderfw/utils/logger"
3
3
  autoload :App, "spiderfw/app"
4
4
  autoload :Controller, "spiderfw/controller/controller"
5
+ autoload :Widget, "spiderfw/widget/widget"
5
6
  autoload :PageController, "spiderfw/controller/page_controller"
6
7
  autoload :Dispatcher, "spiderfw/controller/dispatcher"
7
8
  autoload :Router, "spiderfw/controller/router"
@@ -7,6 +7,7 @@ require 'spiderfw/cmd/commands/console'
7
7
  require 'spiderfw/cmd/commands/test'
8
8
  require 'spiderfw/cmd/commands/setup'
9
9
  require 'spiderfw/cmd/commands/model'
10
+ require 'spiderfw/cmd/commands/config'
10
11
 
11
12
  module Spider; module CommandLine
12
13
 
@@ -17,7 +18,12 @@ module Spider; module CommandLine
17
18
  @cmd.program_name = "spider"
18
19
  @cmd.options = CmdParse::OptionParserWrapper.new do |opt|
19
20
  opt.separator _("Global options:")
20
- opt.on("--verbose", _("Be verbose when outputting info"), "-v" ) {|t| $verbose = true }
21
+ opt.on("--version", _("Output Spider version and exit"), "-v"){ |v|
22
+ require 'spiderfw/version'
23
+ puts Spider::VERSION
24
+ exit
25
+ }
26
+ opt.on("--verbose", _("Be verbose when outputting info"), "-V" ) {|t| $verbose = true }
21
27
  opt.on("--chdir", _("Cd to a directory before running"), "-c"){ |c| Dir.chdir(c) }
22
28
  opt.on("--sets SETS", Array, _("Include configuration sets"), "-s"){ |sets|
23
29
  $SPIDER_CONFIG_SETS = sets
@@ -40,6 +46,7 @@ module Spider; module CommandLine
40
46
  @cmd.add_command(TestCommand.new)
41
47
  @cmd.add_command(SetupCommand.new)
42
48
  @cmd.add_command(ModelCommand.new)
49
+ @cmd.add_command(ConfigCommand.new)
43
50
  # @cmd.add_command(ScaffoldCommand.new)
44
51
  end
45
52
 
@@ -0,0 +1,54 @@
1
+ class ConfigCommand < CmdParse::Command
2
+
3
+
4
+ def initialize
5
+ super( 'config', true, true )
6
+ @short_desc = _("Manage configuration")
7
+
8
+ list = CmdParse::Command.new( 'list', false )
9
+ list.short_desc = _("List configuration options")
10
+ list.options = CmdParse::OptionParserWrapper.new do |opt|
11
+ end
12
+
13
+ list.set_execution_block do |args|
14
+ require 'spiderfw'
15
+ Spider.config.options.sort.each{ |o| puts o }
16
+ end
17
+
18
+ self.add_command(list)
19
+
20
+ info = CmdParse::Command.new('info', false)
21
+ info.short_desc = _("Get information about a configuration option")
22
+ info.set_execution_block do |args|
23
+ require 'spiderfw'
24
+ option = Spider.config.option(args.first)
25
+ if option && option[:params]
26
+ print args[0]
27
+ print ":\n"+option[:description]+"\n" if option[:description] && !option[:description].empty?
28
+ puts
29
+ puts "#{(_('Type')+':').ljust(10)} #{option[:params][:type]}" if option[:params][:type]
30
+ default_str = nil
31
+ if default = option[:params][:default]
32
+ default_str = default.is_a?(Proc) ? _('Dynamic') : default
33
+ end
34
+ puts "#{(_('Default')+':').ljust(10)} #{default_str}" if default_str
35
+ puts "#{(_('Choices')+':').ljust(10)} #{option[:params][:choices].join(', ')}" if option[:params][:choices]
36
+ else
37
+ puts _("Configuration option not found")
38
+ end
39
+ end
40
+
41
+ self.add_command(info)
42
+
43
+ get = CmdParse::Command.new('get', false)
44
+ get.short_desc = _("Get the current value of a configuration option")
45
+ get.set_execution_block do |args|
46
+ require 'spiderfw'
47
+ puts Spider.conf.get(args.first)
48
+ end
49
+
50
+ self.add_command(get)
51
+ end
52
+
53
+ end
54
+
@@ -150,6 +150,26 @@ module Spider
150
150
  end
151
151
  end
152
152
 
153
+ def options
154
+ options = []
155
+ def iterate_options(src, prefix, dst)
156
+ src.each do |key, val|
157
+ full_key = prefix ? "#{prefix}.#{key}" : key
158
+ if val[:params]
159
+ if val[:params][:type] == :conf
160
+ iterate_options(src[key]["x"], full_key+'.x', dst)
161
+ else
162
+ dst << full_key
163
+ end
164
+ else
165
+ iterate_options(src[key], full_key, dst)
166
+ end
167
+ end
168
+ end
169
+ iterate_options(@options, nil, options)
170
+ options
171
+ end
172
+
153
173
  # Sets an allowed configuration option
154
174
  # Possible params are:
155
175
  # -:default the default value for the option; if it is a proc, it will be called
@@ -171,6 +191,16 @@ module Spider
171
191
  o[first] = {:description => description, :params => params}
172
192
  end
173
193
 
194
+ def option(name)
195
+ o = @options
196
+ first, rest = name.split('.', 2)
197
+ while (rest)
198
+ o = (o[first] ||= {})
199
+ first, rest = rest.split('.', 2)
200
+ end
201
+ return o[first]
202
+ end
203
+
174
204
 
175
205
 
176
206
  def get(key)