netzke-core 0.2.7 → 0.2.8

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.2.8
2
+ Support for extra javascripts and stylesheets per widget.
3
+
1
4
  v0.2.7
2
5
  QuickTips get initialized now, as otherwise Ext 2.2.1 doesn't properly destroy() BoxComponents for me.
3
6
 
data/LICENSE CHANGED
@@ -1,20 +1,3 @@
1
- Copyright (c) 2008 Sergei Kozlov
1
+ Copyright (c) 2008-2009 Sergei Kozlov
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3
+ GNU GPL license v3
data/README.mdown CHANGED
@@ -10,4 +10,4 @@ The tutorials: http://blog.writelesscode.com
10
10
 
11
11
  Also see the netzke-basepack project: http://github.com/skozlov/netzke-basepack/tree/master
12
12
 
13
- Copyright (c) 2008-2009 Sergei Kozlov, released under the MIT license
13
+ Copyright (c) 2008-2009 Sergei Kozlov, released under GNU GPL license v3
data/javascripts/core.js CHANGED
@@ -55,14 +55,20 @@ Ext.widgetMixIn = {
55
55
 
56
56
  widgetInit : function(config){
57
57
  this.app = Ext.getCmp('feedback_ghost');
58
+
58
59
  if (config.tools) Ext.each(config.tools, function(i){
59
60
  i.on.click = this[i.on.click].createDelegate(this);
60
61
  }, this);
62
+
61
63
  if (config.actions) Ext.each(config.actions, function(i){
62
64
  this.addEvents(i.handlerName + 'click');
63
65
  i.handler = this.actionHandler.createDelegate(this);
64
66
  }, this);
65
67
 
68
+ if (config.menu) Ext.each(config.menu, function(i){
69
+ this.addMenuItem(i)
70
+ }, this);
71
+
66
72
  // set events
67
73
  this.on('beforedestroy', function(){
68
74
  // clean-up menus
@@ -92,6 +98,16 @@ Ext.widgetMixIn = {
92
98
  };
93
99
  },
94
100
 
101
+ addMenuItem : function(item){
102
+ if (this.hostMenuItem) {
103
+ this.hostMenuItem(item, this);
104
+ } else {
105
+ if (this.ownerCt && this.ownerCt.ownerCt) {
106
+ this.ownerCt.ownerCt.addMenuItem(item)
107
+ }
108
+ }
109
+ },
110
+
95
111
  addMenus:function(menus){
96
112
  if (this.app && !!this.app.hostMenu) {
97
113
  Ext.each(menus, function(menu){this.app.hostMenu(menu, this)}, this)
@@ -130,10 +146,18 @@ Ext.override(Ext.Panel, {
130
146
  var responseObj = Ext.decode(response.responseText);
131
147
  if (responseObj.config) {
132
148
  // we got a normal response
149
+
150
+ // evaluate widget's stylesheets
151
+ if (responseObj.css){
152
+ var linkTag = document.createElement('style')
153
+ linkTag.type = 'text/css';
154
+ linkTag.innerHTML = responseObj.css;
155
+ document.body.appendChild(linkTag);
156
+ }
133
157
 
134
- // evaluate widget's class if it was sent
135
- if (responseObj.classDefinition) {
136
- eval(responseObj.classDefinition);
158
+ // evaluate widget's javascript
159
+ if (responseObj.js) {
160
+ eval(responseObj.js);
137
161
  }
138
162
 
139
163
  responseObj.config.parent = this // we might want to know the parent panel in advance (e.g. to know its size)
@@ -22,4 +22,16 @@ class NetzkeController < ActionController::Base
22
22
  }
23
23
  end
24
24
  end
25
+
26
+ def method_missing(action)
27
+ respond_to do |format|
28
+ format.js {
29
+ render :text => "#{action}.js"
30
+ }
31
+ format.css {
32
+ render :text => "#{action}.css"
33
+ }
34
+ end
35
+ end
36
+
25
37
  end
data/lib/netzke/base.rb CHANGED
@@ -10,6 +10,18 @@ module Netzke
10
10
  class Base
11
11
  module ClassMethods
12
12
 
13
+ # Used to get access to the location of the source file of a Widget, e.g. to automatically include
14
+ # <widget_name>_extras/*.rb files
15
+ def widget_file=(file)
16
+ write_inheritable_attribute(:widget_file, file)
17
+ end
18
+
19
+ def widget_file
20
+ read_inheritable_attribute(:widget_file) || __FILE__
21
+ end
22
+ #
23
+ #
24
+
13
25
  # Global Netzke::Base configuration
14
26
  def config
15
27
  set_default_config({
@@ -66,12 +78,39 @@ module Netzke
66
78
  read_inheritable_attribute(:interface_points)
67
79
  end
68
80
 
81
+ #
82
+ # Include extra code from Ext js library (e.g. examples)
83
+ #
84
+ def ext_js_include(*args)
85
+ included_ext_js = read_inheritable_attribute(:included_ext_js) || []
86
+ args.each {|f| included_ext_js << f}
87
+ write_inheritable_attribute(:included_ext_js, included_ext_js)
88
+ end
89
+
90
+ # def js_include(*args)
91
+ # included_js = read_inheritable_attribute(:included_js) || []
92
+ # args.each {|f| included_js << f}
93
+ # write_inheritable_attribute(:included_js, included_js)
94
+ # end
95
+
96
+ # include eventual extra modules
97
+ def include_extras
98
+ extras_dir = File.join(File.dirname(widget_file), short_widget_class_name.underscore + "_extras")
99
+ file_list = Dir.glob("#{extras_dir}/*.rb")
100
+ for file_name in file_list
101
+ require file_name
102
+ module_name = "#{self.name}Extras::#{File.basename(file_name, ".rb").classify}"
103
+ include module_name.constantize
104
+ end
105
+ end
106
+
69
107
  # returns an instance of a widget defined in the config
70
108
  def instance_by_config(config)
71
109
  widget_class = "Netzke::#{config[:widget_class_name]}".constantize
72
110
  widget_class.new(config)
73
111
  end
74
112
 
113
+ # persistent_config and layout manager classes
75
114
  def persistent_config_manager_class
76
115
  Netzke::Base.config[:persistent_config_manager].constantize
77
116
  rescue NameError
@@ -84,16 +123,6 @@ module Netzke
84
123
  nil
85
124
  end
86
125
 
87
- # include eventual extra modules
88
- def include_extras(file = __FILE__)
89
- extras_dir = File.join(File.dirname(file), short_widget_class_name.underscore + "_extras")
90
- file_list = Dir.glob("#{extras_dir}/*.rb")
91
- for file_name in file_list
92
- require file_name
93
- module_name = "#{self.name}Extras::#{File.basename(file_name, ".rb").classify}"
94
- include module_name.constantize
95
- end
96
- end
97
126
 
98
127
  private
99
128
  def set_default_config(default_config)
@@ -2,9 +2,18 @@ module Netzke
2
2
  module BaseExtras
3
3
  module Interface
4
4
  def get_widget(params = {})
5
- # if browser does not have our component class cached (and all dependencies), send it to him
6
5
  components_cache = (JSON.parse(params[:components_cache]) if params[:components_cache]) || []
7
- {:config => js_config, :class_definition => js_missing_code(components_cache)}
6
+
7
+ js = js_missing_code(components_cache)
8
+ css = css_missing_code(components_cache)
9
+
10
+ css = nil if css.blank?
11
+
12
+ # if browser does not have our widget's (and all its dependencies') class and styles, send it over
13
+ { :config => js_config,
14
+ :js => js,
15
+ :css => css
16
+ }
8
17
  end
9
18
  end
10
19
  end
@@ -56,13 +56,11 @@ module Netzke
56
56
  cached_dependencies.include?(k) ? r : r + "Netzke::#{k}".constantize.js_code(cached_dependencies).strip_js_comments
57
57
  end
58
58
  end
59
-
60
- def dependency_classes
61
- res = []
62
- non_late_aggregatees.each_key do |aggr|
63
- res << aggregatee_instance(aggr).short_widget_class_name
59
+
60
+ def css_missing_code(cached_dependencies = [])
61
+ dependency_classes.inject("") do |r,k|
62
+ cached_dependencies.include?(k) ? r : r + "Netzke::#{k}".constantize.css_code(cached_dependencies)
64
63
  end
65
- res.uniq
66
64
  end
67
65
 
68
66
  #
@@ -176,18 +174,72 @@ JS
176
174
  end
177
175
  end
178
176
 
179
- # all the JS code needed for this class
180
- def js_code(cached_dependencies)
177
+ # returns all extra js-code (as string) required by this widget's class
178
+ def js_included
179
+ # from extjs - defined in the widget class with ext_js_include
180
+ extjs_dir = "#{RAILS_ROOT}/public/extjs" # TODO: make extjs location configurable
181
+ included_ext_js = read_inheritable_attribute(:included_ext_js) || []
182
+ res = included_ext_js.inject("") do |r, path|
183
+ f = File.new("#{extjs_dir}/#{path}")
184
+ r << f.read
185
+ end
186
+
187
+ res << "\n"
188
+
189
+ # from <widget_name>_extras/javascripts - all *.js files found there
190
+ js_dir = File.join(File.dirname(widget_file), short_widget_class_name.underscore + "_extras", "javascripts")
191
+ file_list = Dir.glob("#{js_dir}/*.js")
192
+
193
+ for file_name in file_list
194
+ f = File.new(file_name)
195
+ res << f.read
196
+ end
197
+
198
+ res
199
+ end
200
+
201
+ # all JS code needed for this class, including one from the ancestor widget
202
+ def js_code(cached_dependencies = [])
181
203
  res = ""
182
204
 
183
- # include the dependency if doing JS
184
- res << js_base_class.js_class if js_inheritance && !cached_dependencies.include?(js_base_class.short_widget_class_name)
205
+ # include the base-class javascript if doing JS inheritance
206
+ res << js_base_class.js_code << "\n" if js_inheritance && !cached_dependencies.include?(js_base_class.short_widget_class_name)
207
+
208
+ # include static javascripts
209
+ res << js_included << "\n"
185
210
 
186
211
  # our own JS class definition
187
212
  res << js_class
188
213
  res
189
214
  end
190
215
 
216
+ # returns all css code require by this widget's class
217
+ def css_included
218
+ res = ""
219
+ # from <widget_name>_extras/stylesheets - all *.css files found there
220
+ js_dir = File.join(File.dirname(widget_file), short_widget_class_name.underscore + "_extras", "stylesheets")
221
+ file_list = Dir.glob("#{js_dir}/*.css")
222
+
223
+ for file_name in file_list
224
+ f = File.new(file_name)
225
+ res << f.read
226
+ end
227
+
228
+ res
229
+ end
230
+
231
+ # all JS code needed for this class including the one from the ancestor widget
232
+ def css_code(cached_dependencies = [])
233
+ res = ""
234
+
235
+ # include the base-class javascript if doing JS inheritance
236
+ res << js_base_class.css_code << "\n" if js_inheritance && !cached_dependencies.include?(js_base_class.short_widget_class_name)
237
+
238
+ res << css_included << "\n"
239
+
240
+ res
241
+ end
242
+
191
243
  def this; "this".l; end
192
244
  def null; "null".l; end
193
245
 
@@ -78,4 +78,12 @@ class Symbol
78
78
  def to_js
79
79
  self.to_s.camelize(:lower).to_sym
80
80
  end
81
+ end
82
+
83
+ module ActiveSupport
84
+ class TimeWithZone
85
+ def to_json
86
+ self.to_s(:db).to_json
87
+ end
88
+ end
81
89
  end
data/netzke-core.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{netzke-core}
5
- s.version = "0.2.7"
5
+ s.version = "0.2.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sergei Kozlov"]
9
- s.date = %q{2009-02-13}
9
+ s.date = %q{2009-03-03}
10
10
  s.description = %q{Build ExtJS/Rails widgets with minimum effort}
11
11
  s.email = %q{sergei@writelesscode.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/app/controllers/netzke_controller.rb", "lib/app/models/netzke_layout.rb", "lib/app/models/netzke_preference.rb", "lib/netzke/action_view_ext.rb", "lib/netzke/base.rb", "lib/netzke/base_extras/interface.rb", "lib/netzke/base_extras/js_builder.rb", "lib/netzke/controller_extensions.rb", "lib/netzke/core_ext.rb", "lib/netzke/feedback_ghost.rb", "lib/netzke/routing.rb", "lib/netzke-core.rb", "lib/vendor/facets/hash/recursive_merge.rb", "LICENSE", "README.mdown", "tasks/netzke_core_tasks.rake"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netzke-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Kozlov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-13 00:00:00 +01:00
12
+ date: 2009-03-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15