equipment 0.1.0 → 1.4.84

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGES +9 -0
  2. data/LICENSE +340 -0
  3. data/README +29 -12
  4. data/Rakefile +157 -0
  5. data/TODO +14 -0
  6. data/doc/structure.dia +0 -0
  7. data/doc/structure.png +0 -0
  8. data/lib/camping_ext.rb +72 -0
  9. data/lib/equipment.rb +39 -116
  10. data/lib/ext.rb +33 -0
  11. data/lib/ext/active_record.rb +146 -0
  12. data/lib/ext/basic_auth.rb +15 -15
  13. data/lib/ext/controls.rb +16 -14
  14. data/lib/ext/flash.rb +35 -17
  15. data/lib/ext/form_helpers.rb +46 -0
  16. data/lib/ext/forward.rb +44 -15
  17. data/lib/ext/js_helpers.rb +66 -19
  18. data/lib/ext/logging.rb +61 -0
  19. data/lib/ext/mount.rb +33 -27
  20. data/lib/ext/negociate_content.rb +90 -0
  21. data/lib/ext/og.rb +18 -10
  22. data/lib/ext/og_scaffold.rb +5 -8
  23. data/lib/ext/resource.rb +127 -0
  24. data/lib/ext/security.rb +66 -31
  25. data/lib/ext/sendfile.rb +3 -4
  26. data/lib/ext/settings.rb +243 -0
  27. data/lib/ext/template_view.rb +9 -37
  28. data/lib/ext/use_helper.rb +6 -10
  29. data/lib/ext/view.rb +98 -0
  30. data/lib/ext/view_slot.rb +60 -0
  31. data/lib/mimetype_ext.rb +12 -0
  32. data/lib/more/typecast.rb +288 -0
  33. data/lib/ruby_ext.rb +126 -0
  34. data/share/js/date_ext.js +234 -0
  35. data/share/js/es-confirm.js +23 -0
  36. data/share/js/event-selector.js +145 -0
  37. data/share/js/jquery.js +1793 -0
  38. data/share/js/prototype.js +2012 -0
  39. metadata +50 -35
  40. data/ProjectInfo +0 -55
  41. data/examples/basicauthtest.rb +0 -59
  42. data/examples/erubytest.rb +0 -36
  43. data/examples/flashtest.rb +0 -46
  44. data/examples/index.erb +0 -9
  45. data/examples/mounttest.rb +0 -34
  46. data/examples/ogtest.rb +0 -41
  47. data/examples/patchestest.rb +0 -40
  48. data/examples/sendfiletest.rb +0 -29
  49. data/lib/ext/forms.rb +0 -22
  50. data/lib/ext/patches.rb +0 -130
  51. data/lib/ext/ressource.rb +0 -88
data/TODO ADDED
@@ -0,0 +1,14 @@
1
+ == The global TODO list for Equipment
2
+
3
+ * More docs
4
+ * Fix Og so that it works better with Camping
5
+ * Finish NegociateContent
6
+ * Finish View content-type negociation
7
+ * Finish Resource and Scaffolding
8
+ * Finish Controls
9
+ * TemplateView is almost useless
10
+ * Fix XmlView
11
+ * Logging mechanism
12
+ * Run mode like in Rails
13
+ * Debug mode
14
+
Binary file
Binary file
@@ -0,0 +1,72 @@
1
+ # Basic camping extension
2
+
3
+ require 'camping'
4
+ require 'stringio' # used in Camping but not required
5
+
6
+ # remove some things in Camping
7
+ subs = {
8
+ # "active_support/core_ext/hash" => 'active_support',
9
+ # "metaid " => '',
10
+ # ";autoload:Base,'camping/db'" => '',
11
+ # ";autoload:ActiveRecord,'camping/db'" => '',
12
+ "module Base;include Helpers;" => 'module Base;',
13
+ /module Views;include X,Helpers.end;/m => "module Views end\n",
14
+ /class Mab<Markaby::Builder.*include Views;/m => "class Mab<Markaby::Builder\n",
15
+ }
16
+
17
+ subs.each_pair do |find, replace|
18
+ found = Camping::S.sub!(find, replace)
19
+ raise "`#{find}` not found in Camping. You may use the wrong version of Camping with Equipment" unless found
20
+ end
21
+
22
+ # adds extension
23
+ unless /CampExt/ =~ Camping::S
24
+ Camping::S << "Camping.extend_once Ext, CampExt\n" # `CampExt` to avoid that it gets replaced
25
+ end
26
+
27
+ #puts Camping::S
28
+
29
+ # This module is included if you use camping. Thid module and file is
30
+ # requires to make Equipment work with Camping.
31
+ module CampExt
32
+ # This will allow you to chain create methods.
33
+ # It also restores the the missing modules.
34
+ #
35
+ # == Examplanation
36
+ #
37
+ # When calling YourApp.create, the call order is :
38
+ # * YourApp.create
39
+ # * Last extended module.create
40
+ # * Second last extended module.create
41
+ # * ...
42
+ # * First extended module.create
43
+ #
44
+ # By extending this app first, it will set a blank create method that
45
+ # will ensure that you don't get a NoMethodError when calling `super`
46
+ #
47
+ def create
48
+ puts "INFO: CampExt#create called" if $DBG
49
+ unless self::Base.ancestors.include? self::Helpers
50
+ self::Base.send :include, self::Helpers
51
+ self::Views.send :include, self::Controllers, self::Helpers
52
+ self::Mab.send :include, self::Views
53
+ end
54
+ super
55
+ end
56
+
57
+ # Same as for #create.
58
+ #
59
+ # This method is intended to be used by launchers that support dynamically
60
+ # installing and removing applications.
61
+ #
62
+ def install; false end
63
+
64
+ # See #install.
65
+ def uninstall; false end
66
+
67
+ # Equips global equipments. Make sure they are included before loading your apps.
68
+ def self.extended(app)
69
+ ::Equipment.global_extensions.each{ |ext| ext.equip(app) }
70
+ end
71
+ end
72
+
@@ -2,66 +2,22 @@
2
2
  #
3
3
  # See the README for more informations.
4
4
 
5
- require 'camping'
6
-
7
- =begin # doesn't work
8
- class << Camping
9
- def goes(m)
10
- p super(m)
11
- # app = const_get(m)
12
- # app.extend CampingExt
13
- # app
14
- end
15
- end
16
- =end
17
-
18
- # This module extends every app that uses equipments. It provides some
19
- # useful methods.
20
- module CampingExt
21
- # List of extensions already in the application
22
- def exts; @exts ||= [] end
23
-
24
- # Shortcut method to add an equipment to the app.
25
- #
26
- # You can use YourApp.equip(Extension) instead of
27
- # Extension.equip(YourApp) once this extension is
28
- # installed.
29
- #
30
- def equip(*exts)
31
- exts.each do |ext|
32
- ext.equip(self)
33
- end
34
- self
35
- end
36
-
37
- # This will allow you to chain create methods.
38
- #
39
- # == Examplanation
40
- #
41
- # When calling YourApp.create, the call order is :
42
- # * YourApp.create
43
- # * Last extended module.create
44
- # * Second last extended module.create
45
- # * ...
46
- # * First extended module.create
47
- #
48
- # By extending this app first, it will set a blank create method that
49
- # will ensure that you don't get a NoMethodError when calling `super`
50
- #
51
- def create; end
52
-
53
- # Same as for #create.
54
- #
55
- # This method is intended to be used by launchers that support dynamically
56
- # installing and removing applications.
57
- #
58
- def install; end
59
-
60
- # See #install.
61
- def uninstall; end
5
+ require 'metaid'
6
+ require 'ruby_ext'
7
+ require 'ext'
8
+
9
+ if using? :Camping
10
+ require 'camping_ext'
11
+ elsif not Object.autoload? :Camping
12
+ autoload :Camping, 'camping_ext'
62
13
  end
63
14
 
15
+ # This module provides the facilities for equipments. If included in an app,
16
+ # it will provide a basic set of extensions. If extended in an equipment, it
17
+ # will make it ready to provide new functionnalities to Camping apps.
64
18
  module Equipment
19
+ LIB_PATH = File.expand_path(File.dirname(__FILE__))
20
+ DATA_PATH = File.join(LIB_PATH, '..', 'share')
65
21
 
66
22
  # Utility for equipments. Automatically sets a set of rule for importing
67
23
  # methods, classes, class methods in your application for your extension.
@@ -88,15 +44,17 @@ module Equipment
88
44
  # YourApp.equip(MyUtil)
89
45
  #
90
46
  def equip(app)
91
- raise "Only for Camping apps" unless app.respond_to? :goes
92
- app.extend CampingExt
47
+ # if not app.respond_to? :goes and defined? Camping
48
+ # raise "Cannot equip #{self} to #{app}, only for Camping apps"
49
+ # end
50
+ app.extend Ext unless app.metaclass.ancestors.include? Ext
93
51
 
94
52
  # Only equip once
95
- return false if app.exts.include?(self)
96
- app.exts << self
53
+ return false if app.equipments.include?(self)
54
+ app.equipments << self
97
55
 
98
56
  # dependencies
99
- deps.each { |ext| ext.equip(app) }
57
+ dependencies.each { |ext| ext.equip(app) }
100
58
 
101
59
  puts "** equipped #{self} in #{app}" if $DBG
102
60
 
@@ -114,25 +72,10 @@ module Equipment
114
72
  if mod.public_instance_methods.size > 0 or
115
73
  mod.protected_instance_methods.size > 0 or
116
74
  mod.private_instance_methods.size > 0
117
- app_mod.send :include, mod
118
- puts "Included : #{mod} -> #{app_mod}" if $DBG
119
- # Exceptions until include_deep is working
120
- case name
121
- when "Helpers"
122
- app::Base.send :include, mod
123
- puts "Included : #{mod} -> #{app::Base}" if $DBG
124
- app::Mab.send :include, mod
125
- puts "Included : #{mod} -> #{app::Mab}" if $DBG
126
- if app.const_defined? :V
127
- app::V.send :include, mod
128
- puts "Included : #{mod} -> #{app::V}" if $DBG
129
- end
130
- when "Views"
131
- app::Mab.send :include, mod
132
- puts "Included : #{mod} -> #{app::Mab}" if $DBG
133
- end
134
- end
135
- if mod.constants.size > 0
75
+ app_mod.insert(mod)
76
+ # app_mod.include(mod)
77
+ puts "Inserted : #{mod} -> #{app_mod}" if $DBG
78
+ elsif mod.constants.size > 0
136
79
  mod.transfer_classes_to(app_mod, :force)
137
80
  puts "Cls trans : #{mod} -> #{app_mod}" if $DBG
138
81
  end
@@ -147,49 +90,29 @@ module Equipment
147
90
 
148
91
  # An array of equipment modules on which that equipment depends on for
149
92
  # working. Works with #included.
150
- def deps
151
- @__deps ||= []
93
+ def dependencies
94
+ @__dependencies ||= []
152
95
  end
153
96
 
154
97
  # Asynchronous dependencies for later inclusion in a camping app. Fills
155
98
  # #dependencies for #included.
156
- def depends_on(mod); deps << mod; end
157
-
158
- end
99
+ def depends_on(mod); dependencies << mod; end
159
100
 
160
- class Module
101
+ # If called, your equipment will be available to all apps. Call this
102
+ # before defining any application.
103
+ def equip_all
104
+ ::Equipment.global_extensions << self unless ::Equipment.global_extensions.include? self
105
+ end
161
106
 
162
- # Utility method to transfer all classes of a module into another. It is
163
- # useful when you write Camping extensions. cf. other equipments.
164
- #
165
- # I'm using this to override ServerError and NotFound controllers.
166
- def transfer_classes_to(dest, force=false)
167
- constants.each do |str|
168
- k = const_get(str)
169
- if k.kind_of? Class
170
- dest.send :remove_const, str if force and dest.const_defined? str
171
- dest.const_set str, k.dup unless dest.const_defined? str
172
- end
173
- end
107
+ # If you include Equipment in your app, you'll get some default
108
+ # extensions.
109
+ def self.included(app)
110
+ app.equip Ext::AppUtil, Ext::View, Ext::Forward
174
111
  end
175
112
 
113
+ # List of global extensions from #equip_all
114
+ def self.global_extensions; @global_extensions; end
115
+ @global_extensions = []
176
116
  end
177
117
 
178
- =begin
179
- class Object
180
-
181
- # Sets all instance variables of an object to another
182
- #
183
- # if force is set to true, existing instance variables will be overwritten
184
- def instance_variables_send(obj, force=false)
185
- instance_variables.each do |v|
186
- if force or not obj.instance_variables.include? v
187
- obj.instance_variable_set(v, instance_variable_get(v))
188
- end
189
- end
190
- obj
191
- end
192
- alias :ivs_send :instance_variables_send
193
- end
194
- =end
195
118
 
@@ -0,0 +1,33 @@
1
+ require 'equipment'
2
+
3
+ # This module should be included in your app if you want to use any
4
+ # equipment. It's also used as a namespace for the various extensions.
5
+ module Ext
6
+ class << self
7
+ # Utility method that adds extension mechanism to any module.
8
+ def extendable(mod)
9
+ mod.extend self
10
+ end
11
+ alias_method :endable, :extendable
12
+ end
13
+
14
+ # List of extensions already in the application
15
+ def equipments; @equipments ||= [] end
16
+
17
+ # Shortcut method to add an equipment to the app.
18
+ #
19
+ # You can use YourApp.equip(Extension) instead of
20
+ # Extension.equip(YourApp) once this extension is
21
+ # installed.
22
+ #
23
+ def equip(*exts)
24
+ exts.each{|ext| ext.equip(self)}
25
+ end
26
+
27
+ # Create terminator.
28
+ def create
29
+ puts "INFO: Ext#create called" if $DBG
30
+ self
31
+ end
32
+ end
33
+
@@ -0,0 +1,146 @@
1
+ # Override the camping's autoload
2
+ #autoload :ActiveRecord,'camping_ext'
3
+
4
+ require 'equipment'
5
+
6
+ begin
7
+ ActiveRecord # loads 'camping/db' if camping is loaded.
8
+ rescue NameError # camping not used
9
+ class MissingLibrary < Exception #:nodoc: all
10
+ end
11
+ begin
12
+ require 'active_record'
13
+ rescue LoadError => e
14
+ raise MissingLibrary, "ActiveRecord could not be loaded (is it installed?): #{e.message}"
15
+ end
16
+ end
17
+
18
+ # restoring some adapters
19
+ #RAILS_CONNECTION_ADAPTERS.replace ["mysql", "postgresql", "sqlite", "firebird", "sqlserver", "db2", "oracle", "sybase", "openbase"]
20
+
21
+ #RAILS_CONNECTION_ADAPTERS.each do |adapter|
22
+ # require "active_record/connection_adapters/" + adapter + "_adapter"
23
+ #end
24
+
25
+
26
+ module Ext
27
+ # ActiveRecord extension. Overrides Camping's behaviour.
28
+ #
29
+ # NOTE : This Equipment is usable without Camping.
30
+ #
31
+ # == Dependencies
32
+ #
33
+ # * ActiveRecord
34
+ # * Equipment
35
+ #
36
+ module ActiveRecord
37
+ extend Equipment
38
+
39
+ def self.equip(app)
40
+ unless app.const_defined? :C
41
+ app.module_eval "C=self"
42
+ end
43
+ app.module_eval "module Models;end"
44
+ super
45
+ end
46
+
47
+ module Models
48
+ class AllYourBase < ::ActiveRecord::Base;end
49
+ class << AllYourBase
50
+ # This is a facility to create your schemas.
51
+ #
52
+ # == Example (in your models)
53
+ #
54
+ # class Post < Base
55
+ # self.schema do |c|
56
+ # c.create_table table_name, :force=>true do |t|
57
+ # t.column :title, :string, :limit => 255
58
+ # t.column :body, :text
59
+ # end
60
+ # end
61
+ # end
62
+ #
63
+ def schema(&block)
64
+ @schema = block if block_given?
65
+ @schema
66
+ end
67
+
68
+ # This method checks if your table exists, otherwise it calls
69
+ # the #schema with the model's connection.
70
+ def check_create
71
+ if schema and connection and not table_exists?
72
+ schema.call(connection)
73
+ reset_column_information
74
+ end
75
+ end
76
+
77
+ # The default prefix for Camping model classes is the topmost module name lowercase
78
+ # and followed with an underscore.
79
+ #
80
+ # Tepee::Models::Page.table_name_prefix
81
+ # #=> "tepee_pages"
82
+ #
83
+ def table_name_prefix
84
+ "#{name[/\w+/]}_".downcase.sub(/^(activerecord|camping)_/i,'')
85
+ end
86
+
87
+ # I has to override this method too to get the right table name
88
+ # working
89
+ def reset_table_name #:nodoc:
90
+ table_name = Inflector.underscore(Inflector.demodulize(self.name))
91
+ table_name = Inflector.pluralize(table_name) if pluralize_table_names
92
+ name = "#{table_name_prefix}#{table_name}#{table_name_suffix}"
93
+ set_table_name(name)
94
+ name
95
+ end
96
+
97
+ end
98
+ end
99
+
100
+ # Class methods for you app
101
+ module CClassMethods
102
+ # If set, #create will launch your database with those params.
103
+ attr_accessor :database
104
+
105
+ # Set if #create initialized your database.
106
+ attr_reader :manager
107
+
108
+ # Tries to connect and create the databases.
109
+ def create
110
+ puts "INFO: ActiveRecord#create called" if $DBG
111
+
112
+ if self.database and not @manager
113
+
114
+ # Loads the adapter dynamically
115
+ adapter = self.database[:adapter] || self.database['adapter']
116
+ unless adapter.nil? or RAILS_CONNECTION_ADAPTERS.include? adapter
117
+ require "active_record/connection_adapters/" + adapter + "_adapter"
118
+ RAILS_CONNECTION_ADAPTERS << adapter
119
+ end
120
+
121
+ @manager = self::Models::AllYourBase.establish_connection self.database
122
+ puts "INFO: ActiveRecord connection established : #{@manager.inspect}" if $DBG
123
+ case @logger
124
+ when Logger
125
+ self::Models::AllYourBase.logger = @logger
126
+ when String
127
+ self::Models::AllYourBase.logger = Logger.new(@logger == "-" ? STDOUT : @logger)
128
+ else
129
+ self::Models::AllYourBase.logger = Logger.new(STDOUT)
130
+ end
131
+ end
132
+
133
+ # run check_create on models
134
+ self::Models.constants.each do |c|
135
+ if c != 'Base'
136
+ c = self::Models.const_get(c)
137
+ c.check_create if c.respond_to? :check_create
138
+ end
139
+ end
140
+
141
+ super
142
+ end
143
+ end
144
+ end
145
+ end
146
+