netzke-core 0.12.2 → 0.12.3

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.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v0.12.3 - 2015-08-09
2
+ * Get rid of Ext's viewport warning
3
+ * Uglify components' JS when not in the test/development env
4
+ * Fix stack overflow issue in certain cases
5
+ * Implement inline nesting of components
6
+ * xtype of Netzke components receives additional "netzke" prefix (may potentially break things if you explicitely refer to xtypes)
7
+
1
8
  # v0.12.2 - 2015-06-06
2
9
  * Fix loading multi-instance components
3
10
 
data/Gemfile CHANGED
@@ -17,5 +17,5 @@ end
17
17
  group :development, :test do
18
18
  gem 'web-console', '~> 2.0'
19
19
  gem 'pry-rails'
20
- gem 'netzke-testing', github: 'netzke/netzke-testing'
20
+ gem 'netzke-testing', github: 'netzke/netzke-testing', branch: 'master'
21
21
  end
data/javascripts/ext.js CHANGED
@@ -204,7 +204,7 @@ Ext.define(null, {
204
204
  var parent = this;
205
205
  while (parent) {
206
206
  var cfg = Ext.clone(parent.netzkeClientConfig);
207
- cfg.id = parent.id;
207
+ cfg.component_id = parent.id;
208
208
  this._parentClientConfig.unshift(cfg);
209
209
  parent = parent.netzkeGetParentComponent();
210
210
  }
data/lib/netzke/base.rb CHANGED
@@ -143,6 +143,8 @@ module Netzke
143
143
  # Build complete component configuration
144
144
  configure(config)
145
145
 
146
+ normalize_config
147
+
146
148
  # Check whether the config is valid
147
149
  validate_config(config)
148
150
  end
@@ -118,10 +118,26 @@ module Netzke::Core
118
118
  end
119
119
 
120
120
  def extend_item(item)
121
- super detect_and_normalize(:action, item)
121
+ super detect_and_normalize_action(item)
122
122
  end
123
123
 
124
124
  private
125
+
126
+ def detect_and_normalize_action(item)
127
+ item = {action: item} if item.is_a?(Symbol) && actions[item]
128
+ if item.is_a?(Hash) && action_name = item[:action]
129
+ cfg = actions[action_name]
130
+ cfg.merge!(item)
131
+ if cfg[:excluded]
132
+ {excluded: true}
133
+ else
134
+ item.merge(netzke_action: cfg[:action])
135
+ end
136
+ else
137
+ item
138
+ end
139
+ end
140
+
125
141
  def uri_to_icon(icon)
126
142
  self.class.uri_to_icon(icon)
127
143
  end
@@ -153,7 +153,7 @@ module Netzke
153
153
  # Builds this component's xtype
154
154
  # E.g.: netzkebasepackwindow, netzkebasepackgridpanel
155
155
  def xtype
156
- @klass.name.gsub("::", "").downcase
156
+ "netzke" + @klass.name.gsub("::", "").downcase
157
157
  end
158
158
 
159
159
  # Component's JavaScript class declaration.
@@ -7,7 +7,7 @@ module Netzke::Core
7
7
 
8
8
  def set_defaults!
9
9
  self.item_id ||= name # default item_id
10
- self.klass ||= name.camelize.constantize # default klass
10
+ self.klass ||= self.class_name.try(:constantize) || name.camelize.constantize # default klass
11
11
  end
12
12
  end
13
13
  end
@@ -83,6 +83,8 @@ module Netzke::Core
83
83
  # Declares Base.component, for declaring child componets, and Base#components, which returns a [Hash] of all component configs by name
84
84
  declare_dsl_for :components, config_class: Netzke::Core::ComponentConfig
85
85
 
86
+ attr_accessor :components_in_config
87
+
86
88
  # Loads a component on browser's request. Every Netzke component gets this endpoint.
87
89
  # +params+ should contain:
88
90
  # [cache] an array of component classes cached at the browser
@@ -116,29 +118,29 @@ module Netzke::Core
116
118
  @eagerly_loaded_components ||= components.select{|k,v| components_in_config.include?(k) || v[:eager_loading]}
117
119
  end
118
120
 
119
- # @return [Array<Symbol>] components (by name) referred in config (and thus, required to be instantiated)
120
- def components_in_config
121
- @components_in_config || (normalize_config || true) && @components_in_config
122
- end
123
-
124
121
  # Instantiates a child component by its name.
125
122
  # +params+ can contain:
126
123
  # [client_config] a config hash passed from the client class
127
124
  # [item_id] overridden item_id (used in case of multi-instance loading)
128
125
  def component_instance(name, options = {})
129
- return nil if !respond_to?("#{name}_component")
130
-
131
- cfg = ComponentConfig.new(name, self)
132
- cfg.client_config = options[:client_config] || {}
133
- cfg.item_id = options[:item_id]
134
- cfg.js_id = options[:js_id]
135
- send("#{name}_component", cfg)
136
- cfg.set_defaults!
137
- component_instance_from_config(cfg)
126
+ if respond_to?(:"#{name}_component")
127
+ cfg = ComponentConfig.new(name, self)
128
+ cfg.client_config = options[:client_config] || {}
129
+ cfg.item_id = options[:item_id]
130
+ cfg.js_id = options[:js_id]
131
+ send("#{name}_component", cfg)
132
+ cfg.set_defaults!
133
+ else
134
+ cfg = ComponentConfig.new(name, self)
135
+ cfg.merge!(components[name.to_sym])
136
+ end
137
+
138
+ component_instance_from_config(cfg) if cfg
138
139
  end
139
140
 
140
141
  def component_instance_from_config(c)
141
- c.klass.new(c, self)
142
+ klass = c.klass || c.class_name.constantize
143
+ klass.new(c, self)
142
144
  end
143
145
 
144
146
  # @return [Array<Class>] All component classes that we depend on (used to render all necessary javascripts and stylesheets)
@@ -154,8 +156,8 @@ module Netzke::Core
154
156
  end
155
157
 
156
158
  def extend_item(item)
157
- item = detect_and_normalize(:component, item)
158
- @components_in_config << item[:netzke_component] if include_component?(item)
159
+ item = detect_and_normalize_component(item)
160
+ components_in_config << item[:netzke_component] if include_component?(item)
159
161
  super item
160
162
  end
161
163
 
@@ -167,5 +169,26 @@ module Netzke::Core
167
169
  cmp_config[:eager_loading] != false &&
168
170
  !cmp_config[:excluded]
169
171
  end
172
+
173
+ def detect_and_normalize_component(item)
174
+ item = {component: item} if item.is_a?(Symbol) && components[item]
175
+ if item.is_a?(Hash) && component_name = item[:component]
176
+ cfg = components[component_name]
177
+ cfg.merge!(item)
178
+ if cfg[:excluded]
179
+ {excluded: true}
180
+ else
181
+ # cfg.merge(item).merge(netzke_component: item.delete(:component))
182
+ item.merge(netzke_component: cfg[:component]) # TODO: TEST THIS
183
+ end
184
+ elsif item.is_a?(Hash) && (item[:klass] || item[:class_name])
185
+ # declare component on the fly
186
+ component_name = :"component_#{@implicit_component_index += 1}"
187
+ components[component_name] = item.merge(eager_loading: true) unless item[:excluded]
188
+ {netzke_component: component_name}
189
+ else
190
+ item
191
+ end
192
+ end
170
193
  end
171
194
  end
@@ -102,33 +102,19 @@ module Netzke::Core
102
102
  item.is_a?(Hash) && item[:excluded] ? nil : item
103
103
  end
104
104
 
105
- # Used for detecting actions and components referred by symbols. For example, say, action +do_something+ is
106
- # declared. Then:
107
- #
108
- # item #=> :do_something
109
- # item = detect_and_normalize :action, item
110
- # item #=> {netzke_action: :do_something, text: 'Do it'} # uses action declaration
111
- def detect_and_normalize(thing, item)
112
- if item.is_a?(Symbol) && thing_config = send(thing.to_s.pluralize)[item]
113
- item = {:"netzke_#{thing}" => item, excluded: thing_config[:excluded]}
114
- elsif item.is_a?(Hash)
115
- # replace `action` key with `netzke_action`, which will be looked for at the JS side
116
- item[:"netzke_#{thing}"] = item.delete(thing) if item[thing]
117
- end
118
- item
119
- end
120
-
121
105
  # We'll build a couple of useful instance variables here:
122
106
  #
123
107
  # +components_in_config+ - an array of components (by name) referred in items
124
108
  # +normalized_config+ - a config that has all the config extensions applied
125
109
  def normalize_config
110
+ # @actions = @components = {} # in v1.0 this should replace DSL definition
126
111
  @components_in_config = []
112
+ @implicit_component_index = 0
127
113
  c = config.dup
128
114
  config.each_pair do |k, v|
129
115
  c.delete(k) if self.class.server_side_config_options.include?(k.to_sym)
130
116
  if v.is_a?(Array)
131
- c[k] = v.netzke_deep_map{|el| extend_item(el)}
117
+ c[k] = v.netzke_deep_replace{|el| extend_item(el)}
132
118
  end
133
119
  end
134
120
  @normalized_config = c
@@ -1,3 +1,5 @@
1
+ require 'uglifier'
2
+
1
3
  module Netzke
2
4
  module Core
3
5
  module DynamicAssets
@@ -16,7 +18,7 @@ module Netzke
16
18
  res << f.read
17
19
  end
18
20
 
19
- strip_js_comments(res)
21
+ minify_js(res)
20
22
  end
21
23
 
22
24
  def ext_css
@@ -31,8 +33,12 @@ module Netzke
31
33
  res
32
34
  end
33
35
 
34
- def strip_js_comments(js_string)
35
- js_string
36
+ def minify_js(js_string)
37
+ if ::Rails.env.test? || ::Rails.env.development?
38
+ js_string
39
+ else
40
+ Uglifier.compile(js_string)
41
+ end
36
42
  end
37
43
 
38
44
  private
@@ -106,7 +106,7 @@ module Netzke::Core
106
106
  code = dependency_classes.inject("") do |r,k|
107
107
  cached.include?(k.js_config.xtype) ? r : r + k.js_config.code_with_dependencies
108
108
  end
109
- code.blank? ? nil : Netzke::Core::DynamicAssets.strip_js_comments(code)
109
+ code.blank? ? nil : Netzke::Core::DynamicAssets.minify_js(code)
110
110
  end
111
111
 
112
112
  private
@@ -1,9 +1,6 @@
1
- require 'netzke/core/railz/action_view_ext/ext'
2
1
  module Netzke
3
2
  module Railz
4
3
  module ActionViewExt
5
- include Ext
6
-
7
4
  # A helper to load Netzke and Ext JS files. Usually used in the layout.
8
5
  #
9
6
  # Params:
@@ -23,11 +20,10 @@ module Netzke
23
20
  # Whether to include minified JS and styleshetes. By default is +false+ for Rails development env,
24
21
  # +true+ otherwise
25
22
  def load_netzke(params = {})
26
- Netzke::Core.platform = params[:platform] || :ext
27
23
  params[:minified] = !Rails.env.development? if params[:minified].nil?
28
24
  params[:theme] ||= "crisp"
29
25
 
30
- raw([netzke_css_include(params), netzke_css(params), netzke_js_include(params), netzke_js(params)].join("\n"))
26
+ raw([netzke_html, netzke_css_include(params), netzke_css(params), netzke_js_include(params), netzke_js(params)].join("\n"))
31
27
  end
32
28
 
33
29
  # Use this helper in your views to embed Netzke components. E.g.:
@@ -64,30 +60,62 @@ module Netzke
64
60
  raw(cmp.js_component_html)
65
61
  end
66
62
 
67
- protected
68
-
69
- # Link tags for all the required stylsheets
70
- def netzke_css_include(params)
71
- send :"netzke_#{Netzke::Core.platform}_css_include", params
72
- end
73
-
74
- # Inline CSS specific for the page
75
- def netzke_css(params)
76
- %{
77
- <style type="text/css" media="screen">
78
- #{content_for(:netzke_css)}
79
- </style>} if content_for(:netzke_css).present?
80
- end
81
-
82
- # Script tags for all the required JavaScript
83
- def netzke_js_include(params)
84
- send :"netzke_#{Netzke::Core.platform}_js_include", params
85
- end
86
-
87
- # Inline JavaScript for all Netzke classes on the page, as well as Ext.onReady, which renders Netzke components in this view after the page is loaded
88
- def netzke_js(params = {})
89
- send :"netzke_#{Netzke::Core.platform}_js", params
90
- end
63
+ private
64
+
65
+ def netzke_html
66
+ %{
67
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
68
+ }
69
+ end
70
+
71
+ # Link tags for all the required stylsheets
72
+ def netzke_css_include(params)
73
+ # ExtJS base
74
+ res = ["#{Netzke::Core.ext_uri}/packages/ext-theme-#{params[:theme]}/build/resources/ext-theme-#{params[:theme]}-all.css"]
75
+
76
+ # Netzke-related dynamic css
77
+ res << netzke_ext_path
78
+
79
+ res += Netzke::Core.external_ext_css
80
+
81
+ stylesheet_link_tag(*res)
82
+ end
83
+
84
+ # Inline CSS specific for the page
85
+ def netzke_css(params)
86
+ %{
87
+ <style type="text/css" media="screen">
88
+ #{content_for(:netzke_css)}
89
+ </style>} if content_for(:netzke_css).present?
90
+ end
91
+
92
+ # Script tags for all the required JavaScript
93
+ def netzke_js_include(params)
94
+ res = []
95
+
96
+ # ExtJS
97
+ res << (params[:minified] ? "#{Netzke::Core.ext_uri}/build/ext-all.js" : "#{Netzke::Core.ext_uri}/build/ext-all-debug.js")
98
+
99
+ # Ext I18n
100
+ res << "#{Netzke::Core.ext_uri}/packages/ext-locale/build/ext-locale-#{I18n.locale}" if I18n.locale != :en
101
+
102
+ # Netzke-related dynamic JavaScript
103
+ res << netzke_ext_path
104
+
105
+ javascript_include_tag(*res)
106
+ end
107
+
108
+ # Inline JavaScript for all Netzke classes on the page, as well as Ext.onReady, which renders Netzke components in this view after the page is loaded
109
+ def netzke_js(params = {})
110
+ res = []
111
+ res << content_for(:netzke_js_classes)
112
+
113
+ res << "Ext.onReady(function(){"
114
+ res << content_for(:netzke_on_ready)
115
+ res << "});"
116
+
117
+ javascript_tag(res.join("\n"))
118
+ end
91
119
 
92
120
  end
93
121
 
@@ -3,6 +3,18 @@ class Array
3
3
  self.map{ |el| el.respond_to?(:netzke_deep_map) ? block.call(el.netzke_deep_map(&block)) : block.call(el) }.compact
4
4
  end
5
5
 
6
+ def netzke_deep_replace(&block)
7
+ self.map do |el|
8
+ res = yield(el)
9
+ if res == el
10
+ el.respond_to?(:netzke_deep_replace) ? el.netzke_deep_replace(&block) : el
11
+ # el.respond_to?(:netzke_deep_replace) ? block.call(el.netzke_deep_replace(&block)) : block.call(el)
12
+ else
13
+ res
14
+ end
15
+ end.compact
16
+ end
17
+
6
18
  def netzke_jsonify
7
19
  self.map{ |el| el.is_a?(Array) || el.is_a?(Hash) ? el.netzke_jsonify : el }
8
20
  end
@@ -7,6 +7,25 @@ class Hash
7
7
  end
8
8
  end
9
9
 
10
+ def netzke_deep_replace(&block)
11
+ self.dup.tap do |h|
12
+ h.each_pair do |k,v|
13
+ if v.is_a?(Hash)
14
+ res = yield(v)
15
+ if res == v # no changes, need to go further down
16
+ h[k] = v.netzke_deep_replace(&block) if v.respond_to?('netzke_deep_replace')
17
+ else
18
+ h[k] = res
19
+ end
20
+ else
21
+ if v.is_a?(Array)
22
+ h[k] = v.netzke_deep_replace(&block)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
10
29
  def netzke_jsonify
11
30
  self.inject({}) do |h,(k,v)|
12
31
  new_key = if k.is_a?(Netzke::Core::JsonLiteral)
@@ -19,7 +38,14 @@ class Hash
19
38
  k
20
39
  end
21
40
 
22
- new_value = v.is_a?(Array) || v.is_a?(Hash) ? v.netzke_jsonify : v
41
+ new_value = case v
42
+ when Array, Hash
43
+ v.netzke_jsonify
44
+ when Class, Proc
45
+ v.to_s
46
+ else
47
+ v
48
+ end
23
49
 
24
50
  h.merge(new_key => new_value)
25
51
  end
@@ -119,7 +119,7 @@ module Netzke::Core
119
119
 
120
120
  if components[child_component]
121
121
  client_config = configs.shift || {}
122
- js_id = client_config.delete("id")
122
+ js_id = client_config.delete("component_id")
123
123
  cmp_strong_config = {client_config: client_config, js_id: js_id}
124
124
  component_instance(child_component, cmp_strong_config).invoke_endpoint(action, params, configs)
125
125
  else
@@ -1,5 +1,5 @@
1
1
  module Netzke
2
2
  module Core
3
- VERSION = "0.12.2"
3
+ VERSION = "0.12.3"
4
4
  end
5
5
  end
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.12.2
4
+ version: 0.12.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-06 00:00:00.000000000 Z
12
+ date: 2015-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: uglifier
@@ -72,7 +72,6 @@ files:
72
72
  - lib/netzke/core/json_literal.rb
73
73
  - lib/netzke/core/panel.rb
74
74
  - lib/netzke/core/plugins.rb
75
- - lib/netzke/core/railz/action_view_ext/ext.rb
76
75
  - lib/netzke/core/railz/action_view_ext.rb
77
76
  - lib/netzke/core/railz/controller_extensions.rb
78
77
  - lib/netzke/core/railz/engine.rb
@@ -1,49 +0,0 @@
1
- module Netzke
2
- module Railz
3
- module ActionViewExt
4
- # Implementation of Ext-specific Netzke helpers
5
- module Ext
6
-
7
- private
8
-
9
- def netzke_ext_css_include(params)
10
- # ExtJS base
11
- res = ["#{Netzke::Core.ext_uri}/packages/ext-theme-#{params[:theme]}/build/resources/ext-theme-#{params[:theme]}-all.css"]
12
-
13
- # Netzke-related dynamic css
14
- res << netzke_ext_path
15
-
16
- res += Netzke::Core.external_ext_css
17
-
18
- stylesheet_link_tag(*res)
19
- end
20
-
21
- def netzke_ext_js_include(params)
22
- res = []
23
-
24
- # ExtJS
25
- res << (params[:minified] ? "#{Netzke::Core.ext_uri}/build/ext-all.js" : "#{Netzke::Core.ext_uri}/build/ext-all-debug.js")
26
-
27
- # Ext I18n
28
- res << "#{Netzke::Core.ext_uri}/packages/ext-locale/build/ext-locale-#{I18n.locale}" if I18n.locale != :en
29
-
30
- # Netzke-related dynamic JavaScript
31
- res << netzke_ext_path
32
-
33
- javascript_include_tag(*res)
34
- end
35
-
36
- def netzke_ext_js(params)
37
- res = []
38
- res << content_for(:netzke_js_classes)
39
-
40
- res << "Ext.onReady(function(){"
41
- res << content_for(:netzke_on_ready)
42
- res << "});"
43
-
44
- javascript_tag(res.join("\n"))
45
- end
46
- end
47
- end
48
- end
49
- end