Class: Kiss::Action

Inherits:
Object show all
Includes:
ControllerAccessors, DatabaseAccessors, RequestAccessors, TemplateMethods
Defined in:
lib/kiss/action.rb

Constant Summary collapse

@@template_class =
nil

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TemplateMethods

#data, #data=, #set

Methods included from DatabaseAccessors

#database

Methods included from RequestAccessors

#app, #cookies, #debug, #env, #file_cache, #host, #login, #models, #path_info, #protocol, #pub, #query_string_with_params, #redirect_url, #request_url_with_params, #response, #send_file, #send_response, #session, #set_cookie, #set_exception_cache, #start_benchmark, #stop_benchmark

Methods included from ControllerAccessors

#database, #environment, #models, #public_dir, #upload_dir

Methods included from KissAccessors

#html_escape, #url_escape

Constructor Details

#initialize(request, action_path, extension, collection, object, object_part, object_display_name, breadcrumbs, args, params = {}) ⇒ Action

Creates a new action instance from controller data.



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/kiss/action.rb', line 275

def initialize(request, action_path, extension, collection, object, object_part, object_display_name, breadcrumbs, args, params = {})
  @_request = request
  @_controller = request.controller
  @_path = action_path
  @_extension = extension
  @_object = object
  @_object_part = object_part
  @_args = args
  @_params = params
  
  @_template = self.class.name
  
  @_arg_index = -1
  @_forms = {}
  
  @data = {}
  
  @breadcrumbs = breadcrumbs
  @title =
    is_index? ? (@breadcrumbs.pop.first unless @breadcrumbs.empty?) :
    is_view? ? (@breadcrumbs.pop; object_display_name) :
    is_edit? ? "#{@_object ? 'Edit' : 'Add'} #{collection.first.singularize}" : 
    is_delete? ? "Delete #{collection.first.singularize}" : self.class.part.titlecase
  
  @base_url = app + action_path
  
  after_initialize
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Raises custom error message for missing methods, specifying current action more clearly than standard error message.



266
267
268
269
270
271
272
# File 'lib/kiss/action.rb', line 266

def method_missing(method, *args, &block)
  if method.to_s =~ /\A_class_(\d+)_(.*)/
    __send__ $2.to_sym, $1.to_i, *args, &block
  else
    raise NoMethodError, "undefined method `#{method}'"
  end
end

Class Attribute Details

.authentication_requiredObject (readonly)

Returns the value of attribute authentication_required.



10
11
12
# File 'lib/kiss/action.rb', line 10

def authentication_required
  @authentication_required
end

.base_urlObject (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/kiss/action.rb', line 10

def base_url
  @base_url
end

Returns the value of attribute breadcrumbs.



10
11
12
# File 'lib/kiss/action.rb', line 10

def breadcrumbs
  @breadcrumbs
end

.layoutObject (readonly)

Returns the value of attribute layout.



10
11
12
# File 'lib/kiss/action.rb', line 10

def layout
  @layout
end

Instance Attribute Details

#layoutObject

Returns the value of attribute layout.



250
251
252
# File 'lib/kiss/action.rb', line 250

def layout
  @layout
end

#titleObject

Returns the value of attribute title.



250
251
252
# File 'lib/kiss/action.rb', line 250

def title
  @title
end

Class Method Details

.absolute_uri(path, action_path) ⇒ Object



237
238
239
240
241
# File 'lib/kiss/action.rb', line 237

def absolute_uri(path, action_path)
  # need to add something to action_path before File.dirname, in case
  # action_path ends in /
  path =~ /\A\// ? path : action_path.gsub(/[^\/]*\Z/, '') + path
end

.action_instance_for_path(path, request, params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/kiss/action.rb', line 20

def action_instance_for_path(path, request, params)
  action_subdir = ''
  action_path = '/'
  action_found = false
  args = []
  objects = {}
  breadcrumbs = []
  object = nil
  object_part = nil
  collection = nil
  
  request.redirect_action('/') if path == ''
  
  action_class = self.get_child_class
  
  parts = path.sub(/\A\/*/, '').split(/\/+/)
  parts.push('') if path[-1, 1] == '/'
  
  while part = parts.shift
    action_path += part
    part = (object_part ? 'view' : @@controller.default_action) if part.empty?
    
    # =column syntax not yet supported
    # when adding this support, be sure to change Action#redirect_action also
    
    if part =~ /\A([\w\-\.\+\%]+)\=([\w\-\.\+\%]+)\Z/
      params[$1.url_unescape] = $2.url_unescape
      action_path += '/' + part
      next
    end
    
    if part !~ /\A[\w\-\.]*\Z/i
      raise Kiss::FileNotFoundError::InvalidAction, 'invalid action path'
    end
              
    if redirect = action_class.aliases[part]
      action, options = redirect
      request.redirect_action(
        absolute_uri( action + '/' + parts.join('/'), action_path ),
        options
      )
    end
    
    test_path = @@controller.action_dir + action_subdir + '/' + part
    if @@controller.directory_exists?(test_path)
      action_subdir += '/' + part
      action_class = action_class.get_child_class(part, true)
      object = object_part = nil
      
      collection = action_class.breadcrumb
      
      action_path += '/'
      if action_class.breadcrumbs.empty?
        if File.file?("#{@@controller.action_dir}#{action_class.name}index.rb") ||
            File.file?("#{@@controller.action_dir}#{action_class.name}index.rhtml")
          breadcrumbs << [action_class.breadcrumb, action_path]
        end
      else
        breadcrumbs.push(*action_class.breadcrumbs)
      end
    else
      # remove .rb extension, if any
      part.sub!(/(\.rb)+\Z/, '')
      
      # does part have an extension?
      if part =~ /\A(.+)\.(\w+)\Z/
        extension = $2
        part = $1
      else
        extension = 'rhtml'
      end
      
      test_path = @@controller.action_dir + action_subdir + '/' + part
      if File.file?("#{test_path}.rb") || File.file?("#{test_path}.#{(extension == 'xls') ? 'txt' : extension}")            
        action_found = true
        action_class = action_class.get_child_class(part)
        break
      else
        unless part =~ /\A[\w\.\-]+\Z/
          raise Kiss::FileNotFoundError, "invalid URI"
        end
        
        object_options = action_class.object_options
        if object_options && (object_options[:column] != :id || part =~ /\A\d+\Z/)
          object_part = part
          object = request.dbm[object_options[:class_name]].find(object_options[:column] => object_part)
          objects[object_options[:variable_name]] = object
          
          action_path += '/'
          
          if !object
            raise Kiss::FileNotFoundError, "resource '#{test_path.html_escape}' not found"
          end
          
          object_breadcrumb = action_class.object_breadcrumb
          object_display_name = object[object.class.display_column] ||
            (object.send(object.class.display_column) rescue nil)
          if (object_breadcrumb != false)
            breadcrumbs << [
              (object_breadcrumb.is_a?(Proc) ? object_breadcrumb.call(object) : object_breadcrumb) ||
                object_display_name,
              action_path
            ]
          end
        
          next
        else
          if part == 'view'
            request.redirect_action(path + '..')
          end
          raise Kiss::FileNotFoundError, "resource '#{test_path.html_escape}' not found"
        end
      end
    end
  end
  
  # if no action found, add a trailing slash and try again
  request.redirect_action(path + '/') unless action_found
  
  # keep rest of path_info in args
  args.push(*parts)
  
  action = action_class.new(request, action_path, extension, collection, object, object_part, object_display_name, breadcrumbs, args, params)
  objects.each_pair do |key, value|
    action.instance_variable_set(key, value)
  end
  action
end

.alias_action(part, action, options = {}) ⇒ Object



233
234
235
# File 'lib/kiss/action.rb', line 233

def alias_action(part, action, options = {})
  @_aliases[part.to_s] = [action.to_s, options]
end

.get_child_class(part = nil, is_directory = !part)) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/kiss/action.rb', line 170

def get_child_class(part = nil, is_directory = !part)
  # each subdir must get a subclass of the parent dir class;
  # each subclass has its own @_child_classes hash of its subdirs
  
  subdir = self.name.to_s.sub(/\/\Z/, '')
  name = self.name.to_s + part.to_s + (is_directory ? '/' : '')
  path = name + (is_directory ? '_action' : '') + '.rb'
  parent = self
  
  layout = @layout
  
  auth_path = name
  auth_req = @authentication_required && !@@controller.authenticate_exclude.include?(auth_path)
  
  src, updated = @@controller.file_cache(@@action_dir + path, true)
  
  if updated || !@_child_classes.has_key?(part)
    klass = Class.new(self)
    Kiss.register_class_path(klass, @@action_dir + path)
    klass.class_eval do
      @_subdir = subdir
      @_part = part
      @_name = name
      @_path = "#{subdir}/#{part}"
      @_file_path = path
      @_parent_class = parent
      @_breadcrumb = part ? part.titleize : nil
      
      @layout = layout
      @breadcrumbs = []
      @authentication_required = auth_req
      
      @_aliases = {}
      
      selects_object if part && is_directory 
    end
    
    if src
      klass.class_eval(src, @@action_dir + path)
    end
    @_child_classes[part] = klass
  end
  
  @_child_classes[part]
end

.get_root_class(controller, root_dir) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/kiss/action.rb', line 149

def get_root_class(controller, root_dir)
  parent = self
  klass = Class.new(self)
  Kiss.register_class_path(klass, root_dir)
  klass.class_eval do
    @@action_dir = root_dir
    @@controller = controller
    @@root_class = klass
    
    @_parent_class = parent
    @_subdir = ''
    
    @layout = nil
    @breadcrumbs = []
    @authentication_required = @@controller.authenticate_all ? true : false
    
    @_aliases = {}
  end
  klass
end

.inherited(subclass) ⇒ Object



13
14
15
# File 'lib/kiss/action.rb', line 13

def inherited(subclass)
  subclass.init_child_classes
end

.init_child_classesObject



16
17
18
# File 'lib/kiss/action.rb', line 16

def init_child_classes
  @_child_classes = {}
end

.selects_object(options = {}) ⇒ Object Also known as: select_object, accepts_object, accept_object



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/kiss/action.rb', line 216

def selects_object(options = {})
  if options.has_key?(:variable_name)
    variable_name = options[:variable_name]
    raise 'variable name must be a symbol' unless variable_name.is_a?(Symbol)
    raise 'variable name must start with @' unless variable_name.to_s[0, 1] == '@'
  end
  
  (@_object_options ||= {
    :class_name => @_part.pluralize.to_sym,
    :variable_name => ('@'+@_part.singularize).to_sym,
    :column => :id
  }).merge!(options)
end

Instance Method Details

#absolute_uri(relative_uri) ⇒ Object



484
485
486
# File 'lib/kiss/action.rb', line 484

def absolute_uri(relative_uri)
  self.class.absolute_uri(relative_uri, action_path)
end

#actionObject



643
644
645
# File 'lib/kiss/action.rb', line 643

def action
  self
end

#add_form(attrs = {}, &block) ⇒ Object

Creates and adds form to current action, using specified attributes.



611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# File 'lib/kiss/action.rb', line 611

def add_form(attrs = {}, &block)
  # create form
  temp_form = Kiss::Form.new({
    :name => attrs[:action] || action_path,
    :action => app + request.path_with_query_string,
    :delegate => self
  }.merge(attrs), &block)
  
  # make sure form not already defined for this request
  @_forms ||= {}
  raise "page contains multiple forms named '#{temp_form.name}'" if @_forms.has_key?(temp_form.name)
  @_forms[temp_form.name] = @_form = temp_form
  
  # add data from request to form
  if params['form'] == @_form.name
    @_form. = true
    @_form.params = params
  end
  
  @_form
end

#after_callObject

Callback method: called after action call. Does nothing by default; override this method in your _action.rb or other action files.



583
# File 'lib/kiss/action.rb', line 583

def after_call; end

#after_initializeObject

Callback method: called after action handler initialized. Does nothing by default; override this method in your _action.rb or other action files.



571
# File 'lib/kiss/action.rb', line 571

def after_initialize; end

#app_absolute_path(path) ⇒ Object

Convert specified action path by prefixing current action subdir, unless specified path starts with slash (/).



480
481
482
# File 'lib/kiss/action.rb', line 480

def app_absolute_path(path)
  path !~ /\A\// ? self.class.subdir + '/' + path : path
end

#arg(index) ⇒ Object



256
257
258
# File 'lib/kiss/action.rb', line 256

def arg(index)
  @_args[index]
end

#arg_object(table, *args) ⇒ Object

Returns database model object from specified table, with column matching argument of specified index (defaults to first argument). Raises error if object not found in database or object data does not match desired_values.



357
358
359
360
361
362
363
364
365
366
# File 'lib/kiss/action.rb', line 357

def arg_object(table, *args)
  index = args.first.is_a?(Numeric) ? args.shift : 0
  value = arg(index)
  
  column = args.first.is_a?(Symbol) ? args.shift : nil
  
  get_object_by_value(table, value, column, *args) || begin
    raise Kiss::FileNotFoundError::Object, "could not find #{table.to_s.singularize} with #{column || 'id'}=#{value} (arg #{index})"
  end
end

#arg_object_or_new(table, *args) ⇒ Object

Returns arg_object, or new object of specified table if arg_object fails.



369
370
371
372
373
374
375
376
377
# File 'lib/kiss/action.rb', line 369

def arg_object_or_new(table, *args)
  begin
    arg_object(table, *args)
  rescue
    # remove non-hash arguments, looking for desired_values
    desired_values = args.last.is_a?(Hash) ? args.last : {}
    dbm[table].new(desired_values)
  end
end

#argsObject



260
261
262
# File 'lib/kiss/action.rb', line 260

def args
  @_args
end

#authenticateObject

Does nothing by default; override this method in your _action.rb or other action files to specify authentication behavior.



567
# File 'lib/kiss/action.rb', line 567

def authenticate; end

#before_callObject

Callback method: called before action call. Does nothing by default; override this method in your _action.rb or other action files.



575
# File 'lib/kiss/action.rb', line 575

def before_call; end


304
305
306
307
308
# File 'lib/kiss/action.rb', line 304

def breadcrumbs_html
  @breadcrumbs.select {|b| !b[0].blank? }.map do |crumb|
    %Q(<a href="#{app + crumb[1]}">#{crumb[0]}</a> &gt;)
  end.join(' ')
end

#callObject

Placeholder for generic actions that do nothing but render template. render is called from Kiss#call after this method returns.



579
# File 'lib/kiss/action.rb', line 579

def call; end

#check_desired_values(object, desired_values = nil) ⇒ Object

Raises error if database model object does not match the key=value data in desired_values hash.



321
322
323
324
325
326
327
328
329
330
# File 'lib/kiss/action.rb', line 321

def check_desired_values(object, desired_values = nil)
  if desired_values
    desired_values.each_pair do |key, value|
      unless object[key] == value
        raise "#{object.class.table.to_s.singularize} id=#{object.id} does not have #{key} == #{value.inspect}"
      end
    end
  end
  object
end

#context_classObject



310
311
312
# File 'lib/kiss/action.rb', line 310

def context_class
  Kiss.context_class
end

#force_ssl(options = {}) ⇒ Object Also known as: force_https

Ensure that action requested via SSL; redirects to same action with https protocol if protocol is not https.



587
588
589
590
591
# File 'lib/kiss/action.rb', line 587

def force_ssl(options = {})
  unless protocol == 'https'
    redirect_action(request.path_with_query_string, options.merge( :protocol => 'https' ))
  end
end

#formObject

Returns most recently added form. Shorthand for forms when there is only one form.



635
636
637
# File 'lib/kiss/action.rb', line 635

def form
  @_form
end

#form_action_matchObject

Returns true is ‘form’ param matches current action path.



315
316
317
# File 'lib/kiss/action.rb', line 315

def form_action_match
  return params['form'] == action_path
end

#get_object_by_id(table, id, desired_values = nil) ⇒ Object

Verifies valid id value, selects database model object from specified table with specified id, and checks result to match desired_values.



334
335
336
337
338
339
340
# File 'lib/kiss/action.rb', line 334

def get_object_by_id(table, id, desired_values = nil)
  id = id.to_i
  result = (id > 0) ? dbm[table][id] : nil
  raise "'#{table}' object not found" unless result
  
  check_desired_values(result, desired_values) 
end

#get_object_by_value(table, value, column, *args) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
# File 'lib/kiss/action.rb', line 342

def get_object_by_value(table, value, column, *args)
  desired_values = args.first
  if column
    result = dbm[table].where(column => value).first
    raise "'#{table}' object not found" unless result
    
    check_desired_values(result, desired_values) 
  else
    get_object_by_id(table, value, desired_values)
  end
end

#invoke_action(path, params = {}) ⇒ Object



639
640
641
# File 'lib/kiss/action.rb', line 639

def invoke_action(path, params = {})
  request.invoke_action(path, params).output
end

#is_delete?Boolean

Returns:

  • (Boolean)


606
607
608
# File 'lib/kiss/action.rb', line 606

def is_delete?
  self.class.name == self.class.subdir + '/delete'
end

#is_edit?Boolean

Returns:

  • (Boolean)


602
603
604
# File 'lib/kiss/action.rb', line 602

def is_edit?
  self.class.name == self.class.subdir + '/edit'
end

#is_index?Boolean

Returns:

  • (Boolean)


594
595
596
# File 'lib/kiss/action.rb', line 594

def is_index?
  self.class.name == self.class.subdir + '/index'
end

#is_view?Boolean

Returns:

  • (Boolean)


598
599
600
# File 'lib/kiss/action.rb', line 598

def is_view?
  self.class.name == self.class.subdir + '/view'
end

#new_email(options = {}) ⇒ Object

Creates and invokes new Kiss::Mailer instance to send email message via SMTP.



418
419
420
421
422
# File 'lib/kiss/action.rb', line 418

def new_email(options = {})
  request.new_email({
    :data => data
  }.merge(options))
end

#next_arg_indexObject



379
380
381
# File 'lib/kiss/action.rb', line 379

def next_arg_index
  @_arg_index += 1
end

#next_arg_object(table, *args) ⇒ Object



383
384
385
# File 'lib/kiss/action.rb', line 383

def next_arg_object(table, *args)
  arg_object(table, next_arg_index, *args)
end

#next_arg_object_or_new(table, *args) ⇒ Object



387
388
389
# File 'lib/kiss/action.rb', line 387

def next_arg_object_or_new(table, *args)
  arg_object_or_new(table, next_arg_index, *args)
end

#param_object(table, key = nil, column = nil, *args) ⇒ Object

Returns database model object from specified table, with column matching param of specified key (defaults to singular form of table name). Raises error if object not found in database or object data does not match desired_values.



394
395
396
397
# File 'lib/kiss/action.rb', line 394

def param_object(table, key = nil, column = nil, *args)
  key ||= table.to_s.singularize
  get_object_by_value(table, params[key.to_s], column, *args)
end

#param_object_or_new(table, *args) ⇒ Object

Returns param_object, or new object of specified table if param_object fails.



400
401
402
403
404
405
# File 'lib/kiss/action.rb', line 400

def param_object_or_new(table, *args)
  param_object(table, *args) rescue begin
    desired_values = args.last.is_a?(Hash) ? args.last : {}
    dbm[table].new(desired_values)
  end
end

#redirect_action(action, options = {}) ⇒ Object

Redirects to specified action path, which may also include arguments.



429
430
431
432
433
434
435
436
437
438
# File 'lib/kiss/action.rb', line 429

def redirect_action(action, options = {})
  # need to rewrite this if current action class looks up objects
  # by some other column than id
  if options.has_key?(:object)
    dest_object = options[:object]
    column = self.class.parent_class.object_options[:column]
    action = "#{@_object_part && '../'}#{"#{dest_object[column]}/" if dest_object}#{action}"
  end
  request.redirect_action( absolute_uri(action), options )
end

#redirect_index(options = {}) ⇒ Object

Redirects to index of the same action group.



441
442
443
# File 'lib/kiss/action.rb', line 441

def redirect_index(options = {})
  redirect_action('', options.merge(:object => nil))
end

#redirect_object(object = nil, options = {}) ⇒ Object Also known as: redirect_view

Redirects to the view action on the object.



446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/kiss/action.rb', line 446

def redirect_object(object = nil, options = {})
  if object.is_a?(Hash)
    options = object
    object = nil
  end
  object ||= options[:object] || @_object
  if object && !object.new?
    redirect_action('', {:object => object}.merge(options))
  else
    redirect_index(options)
  end
end

#redirect_pop(options = {}) ⇒ Object Also known as: redirect_breadcrumb

Redirects to index of the same action group.



461
462
463
464
465
466
467
# File 'lib/kiss/action.rb', line 461

def redirect_pop(options = {})
  if @breadcrumbs.empty?
    redirect_index(options)
  else
    redirect_action(@breadcrumbs.last.last, options)
  end
end

#render(options = {}) ⇒ Object

Render and return response to Rack.



557
558
559
560
561
562
563
# File 'lib/kiss/action.rb', line 557

def render(options = {})
  Dir.chdir(controller.project_dir)
  
  @_output = render_to_string(options)
  @_output_options = options
  throw :kiss_action_done
end

#render_action(path, options = {}) ⇒ Object



470
471
472
473
474
475
476
# File 'lib/kiss/action.rb', line 470

def render_action(path, options = {})
  action = request.render_action(
    absolute_uri(path),
    options[:params] || {}, {:layout => nil}
  )
  action.output
end

#render_to_string(*args) ⇒ Object

Return string result from rendering specified string or template options.



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/kiss/action.rb', line 489

def render_to_string(*args)
  args = args.clone
  options = args.last.is_a?(Hash) ? args.pop : {}
  if args.first.is_a?(String)
    options = {:template => args.first}.merge(options)
  end
  
  if options[:text]
    return options[:text].to_s
  end
  
  if options.is_a?(Hash)
    @title = options[:title] if options.has_key?(:title)
    @layout = options[:layout] if options.has_key?(:layout)
    @breadcrumbs = options[:breadcrumbs] if options.has_key?(:breadcrumbs)
  end
  
  @@template_class ||= Kiss::Template.get_root_class(controller, controller.template_dir)
  
  content = options[:content].is_a?(String) ? begin
    template_class = @@template_class.get_subclass_from_path(self.class.subdir, 'rhtml')
    options[:content]
  end : begin
    path = @@template_class.get_template_path(
      {
        :template => template,
        :subdir => self.class.subdir,
        :extension => (extension == 'xls') ? 'txt' : extension
      }.merge(options)
    )
    template_class = @@template_class.get_subclass_from_path(path)
    template_class.new(request, self).call
  end
  
  unless defined?(@layout)
    @layout = extension == 'rhtml' ? self.class.layout || (template_class && template_class.layout) || '/_layout.rhtml' : nil
  end
  
  i = 0
  while @layout
    ext = options[:extension] || extension
    layout_path = @@template_class.get_template_path(
      :template => @layout,
      :subdir => self.class.subdir,
      :extension => (ext == 'xls') ? 'txt' : ext
    ) rescue break
    
    # cache layout for comparison after render
    prev_layout = @layout
    
    # process layout file
    layout_class = @@template_class.get_subclass_from_path(layout_path)
    content = layout_class.new(request, self).call(content)
    
    if @layout == prev_layout
      @layout = layout_class.parent_class.parent_class.layout
    end
  end
  
  # add a base tag in case of arguments appended to request URI
  if extension == 'rhtml' && (base_url = options.has_key?(:base_url) ? options[:base_url] : @base_url)
    content = content.prepend_html(%Q(<base href="#{base_url}" />), 'head')
  end
  
  content
end

#send_email(options = {}) ⇒ Object



424
425
426
# File 'lib/kiss/action.rb', line 424

def send_email(options = {})
  new_email(options).send
end

#validate_arg(format, index = 0, options = {}) ⇒ Object

Validates argument of specified index against specified format.



413
414
415
# File 'lib/kiss/action.rb', line 413

def validate_arg(format, index = 0, options = {})
  @_args[index].validate(format, options.merge(:label => "arg #{index}"))
end

#validate_param(key, format, options = {}) ⇒ Object

Validates param of specified key against specified format.



408
409
410
# File 'lib/kiss/action.rb', line 408

def validate_param(key, format, options = {})
  @_params[key.to_s].validate(format, options.merge(:label => "param '#{key}'"))
end