Module: Netzke::Railz::ActionViewExt

Defined in:
lib/netzke/core/railz/action_view_ext.rb

Instance Method Summary collapse

Instance Method Details

#load_netzke(params = {}) ⇒ Object

A helper to load Netzke and Ext JS files. Usually used in the layout.

Params:

theme

The theme to apply. E.g.:

<%= load_netzke theme: "classic" %>

Themes shipped with Ext JS:

  • “neptune” (default in Netzke)

  • “classic”

  • “gray”

  • “access”

minified

Whether to include minified JS and styleshetes. By default is false for Rails development env, true otherwise



22
23
24
25
26
27
# File 'lib/netzke/core/railz/action_view_ext.rb', line 22

def load_netzke(params = {})
  params[:minified] = !Rails.env.development? if params[:minified].nil?
  params[:theme] ||= "triton"

  raw([netzke_html, netzke_css_include(params), netzke_css(params), netzke_js_include(params), netzke_js(params)].join("\n"))
end

#netzke(name, config = {}) ⇒ Object

Use this helper in your views to embed Netzke components. E.g.:

netzke :my_grid, :class_name => "Basepack::GridPanel", :columns => [:id, :name, :created_at]


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/netzke/core/railz/action_view_ext.rb', line 31

def netzke(name, config = {})
  @rendered_classes ||= []

  # If we are the first netzke call on the page, reset components hash in the session.
  # WON'T WORK, because it breaks the browser "back" button
  # if @rendered_classes.empty?
  #   Netzke::Core.reset_components_in_session
  # end

  class_name = config[:class_name] ||= name.to_s.camelcase

  config[:name] = name

  cmp = Netzke::Base.instance_by_config(config)

  # Register the component in session
  session[:netzke_components] ||= {}
  session[:netzke_components][cmp.js_id.to_sym] = config

  content_for :netzke_js_classes, raw(cmp.js_missing_code(@rendered_classes))

  content_for :netzke_css, raw(cmp.css_missing_code(@rendered_classes))

  content_for :netzke_on_ready, raw("#{cmp.js_component_instance}\n\n#{cmp.js_component_render}")

  # Now mark all this component's dependency classes (including self) as rendered (by storing their xtypes), so that we only generate a class once per view
  @rendered_classes = (@rendered_classes + cmp.dependency_classes.map{|k| k.client_class_config.xtype}).uniq

  # Return the html for this component
  raw(cmp.js_component_html)
end