Class Mack::JavaScript::ScriptGenerator
In: lib/mack-javascript/helpers/script_generator.rb
Parent: Object

Methods

<<   ajax   ajax_framework   alert   assign   call   delay   framework=   function   hide   insert_html   new   remove   replace   replace_html   select   selector_framework   show   to_s   toggle  

Attributes

session_id  [R] 

Public Class methods

[Source]

     # File lib/mack-javascript/helpers/script_generator.rb, line 123
123:         def ajax_framework
124:           ivar_cache('ajax_framework') do
125:             "Mack::JavaScript::Framework::#{framework_name}Ajax".constantize
126:           end
127:         end

[Source]

     # File lib/mack-javascript/helpers/script_generator.rb, line 135
135:         def framework=(args)
136:           @ajax_framework = nil
137:           @selector_framework = nil
138:           @@framework_name = args.camelcase
139:         end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 9
 9:       def initialize(session_id = nil)
10:         @lines = []
11:         @session_id = session_id
12:       end

[Source]

     # File lib/mack-javascript/helpers/script_generator.rb, line 129
129:         def selector_framework
130:           ivar_cache('selector_framework') do
131:             "Mack::JavaScript::Framework::#{framework_name}Selector".constantize
132:           end
133:         end

Public Instance methods

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 38
38:       def <<(s, options = {})
39:         if options[:add_to_last]
40:           @lines.last << s
41:         else
42:           @lines << s
43:         end
44:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 31
31:       def ajax(options)
32:         unless configatron.mack.disable_forgery_detector || !session_id
33:           options.merge!(:authenticity_token => Mack::Utils::AuthenticityTokenDispenser.instance.dispense_token(session_id))
34:         end
35:         self << self.class.ajax_framework.remote_function(options)
36:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 52
52:       def alert(message)
53:         self << "alert('#{message}')"
54:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 67
67:       def assign(variable, value)
68:         self << "#{variable} = #{value.to_json}"
69:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 56
56:       def call(*args, &block)
57:         s = args.shift + '('
58:         a = []
59:         args.each {|arg| a << arg.to_json}
60:         self << s + a.join(',') + ')'
61:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 71
71:       def delay(seconds = 1, &block)
72:         self << "setTimeout(#{function.body(&block)}, #{(seconds * 1000).to_i})"
73:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 63
63:       def function(*args)
64:         Mack::JavaScript::Function.new(session_id, *args)
65:       end

[Source]

     # File lib/mack-javascript/helpers/script_generator.rb, line 107
107:       def hide(*ids)
108:         deprecate_method(:hide, 'page.select("#id1", "#id2").hide', '0.8.3')
109:         ids = [ids] if ids.is_a? String
110:         ids.collect! {|id| "##{id}"}
111:         self.select(*ids).hide
112:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 78
78:       def insert_html(position, id, html)
79:         deprecate_method(:insert_html, 'page.select("#id").insert(position, html)', '0.8.3')
80:         self.select("##{id}").insert(position, html)
81:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 93
93:       def remove(*ids)
94:         deprecate_method(:remove, 'page.select("#id1", "#id2").remove', '0.8.3')
95:         ids = [ids] if ids.is_a? String
96:         ids.collect! {|id| "##{id}"}
97:         self.select(*ids).remove
98:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 88
88:       def replace(id, html)
89:         deprecate_method(:replace, 'page.select("#id").replace(:outer, html)', '0.8.3')
90:         self.select("##{id}").replace(:outer, html).to_s
91:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 83
83:       def replace_html(id, html)
84:         deprecate_method(:replace_html, 'page.select("#id").replace(:inner, html)', '0.8.3')
85:         self.select("##{id}").replace(:inner, html).to_s
86:       end

selects elements on the page using css3 selectors For more info: www.w3.org/TR/css3-selectors/ A few useful examples: ‘div’ would select all divs. ’.full’ would select all elements with class ‘full’. ‘div.blah’ would select all divs with class ‘blah’. ‘foo’ would select the element with id ‘foo‘

select can take multiple selector strings. For instance page.select(‘ul.blah’, ‘foo’, ’.full’) would give you access to a collection of elements containing all uls with class ‘blah’, the element with id ‘foo’ and every element with class ‘full’. See JquerySelector or PrototypeSelector for available methods on the returned collection.

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 27
27:       def select(*selector)
28:         self.class.selector_framework.new(self, *selector)
29:       end

[Source]

     # File lib/mack-javascript/helpers/script_generator.rb, line 100
100:       def show(*ids)
101:         deprecate_method(:show, 'page.select("#id1", "#id2").show', '0.8.3')
102:         ids = [ids] if ids.is_a? String
103:         ids.collect! {|id| "##{id}"}
104:         self.select(*ids).show
105:       end

[Source]

    # File lib/mack-javascript/helpers/script_generator.rb, line 46
46:       def to_s
47:         string = @lines.join(';')
48:         string << ';' unless string =~ /;$/
49:         string
50:       end

[Source]

     # File lib/mack-javascript/helpers/script_generator.rb, line 114
114:       def toggle(*ids)
115:         deprecate_method(:toggle, 'page.select("#id1", "#id2").toggle', '0.8.3')
116:         ids = [ids] if ids.is_a? String
117:         ids.collect! {|id| "##{id}"}
118:         self.select(*ids).toggle
119:       end

[Validate]