Module: OMF::Web::Theme

Extended by:
Base::Loggable
Defined in:
lib/omf-web/theme.rb,
lib/omf-web/theme/bright/page.rb,
lib/omf-web/theme/abstract_page.rb,
lib/omf-web/theme/bright/widget_page.rb,
lib/omf-web/theme/bright/code_renderer.rb,
lib/omf-web/theme/bright/data_renderer.rb,
lib/omf-web/theme/bright/flow_renderer.rb,
lib/omf-web/theme/bright/text_renderer.rb,
lib/omf-web/theme/bright/widget_chrome.rb,
lib/omf-web/theme/bright/layout_renderer.rb,
lib/omf-web/theme/bright/tabbed_renderer.rb,
lib/omf-web/theme/bright/stacked_renderer.rb,
lib/omf-web/theme/bright/mustache_renderer.rb,
lib/omf-web/theme/bright/UNUSED/widget_page.rb,
lib/omf-web/theme/bright/one_column_renderer.rb,
lib/omf-web/theme/bright/two_columns_renderer.rb

Defined Under Namespace

Classes: AbstractPage, CodeRenderer, DataRenderer, FlowRenderer, LayoutRenderer, MustacheRenderer, OneColumnRenderer, Page, StackedRenderer, StackedRendererHelper, TabbedRenderer, TextRenderer, TwoColumnsRenderer, WidgetChrome, WidgetPage

Constant Summary collapse

DEFAULT_THEME =
'omf-web/theme/bright'
@@search_order =

default theme

[DEFAULT_THEME]
@@loaded =
{}
@@additional_renderers =
{}

Class Method Summary collapse

Class Method Details

.create_renderer(name, widget) ⇒ Object

Return a named renderer for this theme initialised with ‘widget’



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/omf-web/theme.rb', line 43

def self.create_renderer(name, widget)
  name = name.to_sym
  @@search_order.each do |theme|
    if tr = @@additional_renderers[theme.to_s]
      if klass = tr[name]
        #self.require(name)
        return klass.new(widget)
      end
    end
  end
  raise "Can't find class implementing renderer '#{name}' in '#{@@search_order.join(', ')}'"
end

.include_css(css_file) ⇒ Object



22
23
24
25
# File 'lib/omf-web/theme.rb', line 22

def self.include_css(css_file)
  ::Kernel.require 'omf-web/theme/abstract_page'
  OMF::Web::Theme::AbstractPage.add_depends_on(:css, "/resource/#{css_file}")
end

.register_renderer(name, klass, theme = DEFAULT_THEME) ⇒ Object



27
28
29
30
# File 'lib/omf-web/theme.rb', line 27

def self.register_renderer(name, klass, theme = DEFAULT_THEME)
  tr = @@additional_renderers[theme.to_s] ||= {}
  tr[name] = klass
end

.require(name) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/omf-web/theme.rb', line 56

def self.require(name)
  name = name.to_sym
  return if @@loaded[name]
  @@search_order.each do |theme|
    begin
      # check if there is a registered renderer. Assumes to be already loaded
      unless (@@additional_renderers[theme.to_s] || {})[name]
        #puts "Checking for '#{theme}/#{name}.rb'"
        Kernel::require "#{theme}/#{name}"
      end
      @@loaded[name] = true
      debug "Using renderer '#{theme}/#{name}'"
      return
    rescue LoadError => le
      # Move on to the next one
      #puts ">>>> #{le}"
    end
  end
  raise "Can't find theme component '#{name}' in '#{@@search_order.join(', ')}'"
end

.search_order=(search_order) ⇒ Object

Set additional themes to search in the given order for implementations of renderes. Allows for partial override in new themes.



36
37
38
39
# File 'lib/omf-web/theme.rb', line 36

def self.search_order=(search_order)
  @@loaded = {}
  @@search_order = search_order if search_order
end

.theme=(theme) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/omf-web/theme.rb', line 11

def self.theme=(theme)
  if theme
    unless theme.match '.*/'
      theme = "omf-web/theme/#{theme}" # add default name space
    end
    @@loaded = {}
    @@search_order = [theme]
    Kernel::require "#{theme}/init"
  end
end