Module: Spider::ControllerMixins::Visual::ClassMethods
- Defined in:
- lib/spiderfw/controller/mixins/visual.rb
Instance Method Summary collapse
- #assets ⇒ Object
- #current_default_template ⇒ Object
- #get_layout(action) ⇒ Object
- #layout(name, params = {}) ⇒ Object
- #layout_params ⇒ Object
- #layouts ⇒ Object
- #load_layout(path) ⇒ Object
- #load_template(name, cur_path = nil, owner = nil, search_paths = nil) ⇒ Object
- #load_template_from_path(path, definer) ⇒ Object
- #no_layout(check) ⇒ Object
- #template_exists?(name, paths = nil) ⇒ Boolean
- #template_paths ⇒ Object
Instance Method Details
#assets ⇒ Object
604 605 606 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 604 def assets [] end |
#current_default_template ⇒ Object
600 601 602 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 600 def current_default_template Spider::Inflector.underscore(self.to_s.split('::')[-1]) end |
#get_layout(action) ⇒ Object
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 517 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_s.split('/').first.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
506 507 508 509 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 506 def layout(name, params={}) self.layouts << name self.layout_params[name] = params end |
#layout_params ⇒ Object
502 503 504 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 502 def layout_params @layout_params ||= {} end |
#layouts ⇒ Object
498 499 500 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 498 def layouts @layouts ||= [] end |
#load_layout(path) ⇒ Object
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 581 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) raise "Layout #{path} not found" unless resource && resource.path 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 |
#load_template(name, cur_path = nil, owner = nil, search_paths = nil) ⇒ Object
551 552 553 554 555 556 557 558 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 551 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 = load_template_from_path(resource.path, resource.definer) return t end |
#load_template_from_path(path, definer) ⇒ Object
560 561 562 563 564 565 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 560 def load_template_from_path(path, definer) t = Spider::Template.new(path) t.owner_class = self t.definer_class = definer t end |
#no_layout(check) ⇒ Object
512 513 514 515 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 512 def no_layout(check) @no_layout ||= [] @no_layout << check end |
#template_exists?(name, paths = nil) ⇒ Boolean
568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 568 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_paths ⇒ Object
537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/spiderfw/controller/mixins/visual.rb', line 537 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 |