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

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) assets



571
572
573
# File 'lib/spiderfw/controller/mixins/visual.rb', line 571

def assets
    []
end

- (Object) current_default_template



567
568
569
# File 'lib/spiderfw/controller/mixins/visual.rb', line 567

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

- (Object) get_layout(action)



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/spiderfw/controller/mixins/visual.rb', line 490

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

- (Object) layout(name, params = {})



479
480
481
482
# File 'lib/spiderfw/controller/mixins/visual.rb', line 479

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

- (Object) layout_params



475
476
477
# File 'lib/spiderfw/controller/mixins/visual.rb', line 475

def layout_params
    @layout_params ||= {}
end

- (Object) layouts



471
472
473
# File 'lib/spiderfw/controller/mixins/visual.rb', line 471

def layouts
    @layouts ||= []
end

- (Object) load_layout(path)



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/spiderfw/controller/mixins/visual.rb', line 549

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.no_asset_profiles(*params[:no_asset_profiles]) if params[:no_asset_profiles]
    layout.only_asset_profiles(params[:only_asset_profiles]) if params[:only_asset_profiles]
    layout
end

- (Object) load_template(name, cur_path = nil, owner = nil, search_paths = nil)



524
525
526
527
528
529
530
531
532
533
534
# File 'lib/spiderfw/controller/mixins/visual.rb', line 524

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

- (Object) no_layout(check)



485
486
487
488
# File 'lib/spiderfw/controller/mixins/visual.rb', line 485

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

- (Boolean) template_exists?(name, paths = nil)



536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/spiderfw/controller/mixins/visual.rb', line 536

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

- (Object) template_paths



510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/spiderfw/controller/mixins/visual.rb', line 510

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