Module: Spider::ControllerMixins::Visual::ClassMethods

Defined in:
lib/spiderfw/controller/mixins/visual.rb

Instance Method Summary collapse

Instance Method Details

#assetsObject



550
551
552
# File 'lib/spiderfw/controller/mixins/visual.rb', line 550

def assets
    []
end

#current_default_templateObject



546
547
548
# File 'lib/spiderfw/controller/mixins/visual.rb', line 546

def current_default_template
    Spider::Inflector.underscore(self.to_s.split('::')[-1])
end

#get_layout(action) ⇒ Object



471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/spiderfw/controller/mixins/visual.rb', line 471

def get_layout(action)
    if (@no_layout)
        @no_layout.each do |check|
            return nil if check_action(action, check)
        end
    end
    action = (action && !action.empty?) ? action.to_sym : self.default_action
    layouts.each do |name|
        params = @layout_params[name]
        if (params[:for])
            next unless check_action(action, params[:for])
        end
        if (params[:except])
            next if check_action(action, params[:except])
        end
        return name
    end
    return nil
end

#layout(name, params = {}) ⇒ Object



460
461
462
463
# File 'lib/spiderfw/controller/mixins/visual.rb', line 460

def layout(name, params={})
    self.layouts << name
    self.layout_params[name] = params
end

#layout_paramsObject



456
457
458
# File 'lib/spiderfw/controller/mixins/visual.rb', line 456

def layout_params
    @layout_params ||= {}
end

#layoutsObject



452
453
454
# File 'lib/spiderfw/controller/mixins/visual.rb', line 452

def layouts
    @layouts ||= []
end

#load_layout(path) ⇒ Object



530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/spiderfw/controller/mixins/visual.rb', line 530

def load_layout(path)
    unless respond_to?(:layout_path)
        raise NotImplementedError, "The layout_path class method must be implemented by object using the Visual mixin, but #{self} does not"
    end
    params = self.layout_params[path] || {}
    if (path.is_a?(Symbol))
        path = Spider::Layout.named_layouts[path]
    end
    resource = Spider::Template.find_resource(path+'.layout', layout_path, self)
    layout = Spider::Layout.new(resource.path)
    layout.definer_class = resource.definer
    layout.asset_set = params[:assets] if params[:assets]
    layout
end

#load_template(name, cur_path = nil, owner = nil, search_paths = nil) ⇒ Object



505
506
507
508
509
510
511
512
513
514
515
# File 'lib/spiderfw/controller/mixins/visual.rb', line 505

def load_template(name, cur_path=nil, owner=nil, search_paths=nil)
    owner ||= self
    search_paths ||= template_paths
    resource = Spider::Template.find_resource(name, cur_path, owner, search_paths)
    raise "Template #{name} not found" unless resource && resource.path
    t = Spider::Template.new(resource.path)
    t.owner_class = self
    t.definer_class = resource.definer
    return t

end

#no_layout(check) ⇒ Object



466
467
468
469
# File 'lib/spiderfw/controller/mixins/visual.rb', line 466

def no_layout(check)
    @no_layout ||= []
    @no_layout << check
end

#template_exists?(name, paths = nil) ⇒ Boolean

Returns:

  • (Boolean)


517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/spiderfw/controller/mixins/visual.rb', line 517

def template_exists?(name, paths=nil)
    if (name[0..5] == 'SPIDER' || name[0..3] == 'ROOT')
        name.sub!('SPIDER', $SPIDER_PATH).sub!('ROOT', Spider.paths[:root])
        return true if File.exist?(name)
    end
    paths ||= template_paths
    paths.each do |path|
        full = path+'/'+name+'.shtml'
        return true if File.exist?(full)
    end
    return false
end

#template_pathsObject



491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/spiderfw/controller/mixins/visual.rb', line 491

def template_paths
    unless respond_to?(:template_path)
        raise NotImplementedError, "The template_path class method must be implemented by object using the Visual mixin, but #{self} does not"
    end
    paths = [template_path]
    s = self.superclass
    while (s && s.subclass_of?(Visual) && s.app && s.respond_to?(:template_path))
        paths << s.template_path
        s = s.superclass
    end
    return paths
end