Class: OMF::Web::Theme::AbstractPage
- Inherits:
-
Erector::Widget
- Object
- Erector::Widget
- OMF::Web::Theme::AbstractPage
- Defined in:
- lib/omf-web/theme/abstract_page.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
- #collect_data_sources(dsa) ⇒ Object
- #content ⇒ Object
-
#data_source_widgets ⇒ Object
Return an array of widgets to collect data sources from.
-
#initialize(widget, opts) ⇒ AbstractPage
constructor
A new instance of AbstractPage.
- #render_additional_headers ⇒ Object
- #render_data_source(ds) ⇒ Object
- #render_data_sources ⇒ Object
- #render_flash ⇒ Object
- #to_html(opts = {}) ⇒ Object
Constructor Details
#initialize(widget, opts) ⇒ AbstractPage
Returns a new instance of AbstractPage.
35 36 37 38 39 40 |
# File 'lib/omf-web/theme/abstract_page.rb', line 35 def initialize(, opts) #puts "KEYS>>>>> #{opts.keys.inspect}" super opts @widget = @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
29 30 31 |
# File 'lib/omf-web/theme/abstract_page.rb', line 29 def opts @opts end |
Class Method Details
.add_depends_on(type, url) ⇒ Object
31 32 33 |
# File 'lib/omf-web/theme/abstract_page.rb', line 31 def self.add_depends_on(type, url) depends_on type.to_sym, url end |
Instance Method Details
#collect_data_sources(dsa) ⇒ Object
112 113 114 |
# File 'lib/omf-web/theme/abstract_page.rb', line 112 def collect_data_sources(dsa) dsa end |
#content ⇒ Object
42 43 |
# File 'lib/omf-web/theme/abstract_page.rb', line 42 def content end |
#data_source_widgets ⇒ Object
Return an array of widgets to collect data sources from
68 69 70 |
# File 'lib/omf-web/theme/abstract_page.rb', line 68 def [@widget] end |
#render_additional_headers ⇒ Object
108 109 110 |
# File 'lib/omf-web/theme/abstract_page.rb', line 108 def render_additional_headers #"\n\n<link href='/resource/css/incoming.css' media='all' rel='stylesheet' type='text/css' />\n" end |
#render_data_source(ds) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/omf-web/theme/abstract_page.rb', line 100 def render_data_source(ds) dspa = OMF::Web::DataSourceProxy.for_source(ds) dspa.collect do |dsp| dsp.reset() dsp.to_javascript(ds) end.join("\n") end |
#render_data_sources ⇒ Object
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 |
# File 'lib/omf-web/theme/abstract_page.rb', line 72 def render_data_sources return unless @widget require 'omf_oml/table' require 'set' dss = Set.new .each do |w| w.collect_data_sources(dss) end return if dss.empty? js = dss.map do |ds| render_data_source(ds) end # Calling 'javascript' doesn't seem to work here. No idea why, so let's do it by hand %{ <script type="text/javascript"> // <![CDATA[ require(['omf/data_source_repo'], function(ds) { #{js.join("\n")} }); // ]]> </script> } end |
#render_flash ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/omf-web/theme/abstract_page.rb', line 45 def render_flash return unless @flash if @flash[:notice] div :class => 'flash_notice flash' do text @flash[:notice] end end if @flash[:alert] div :class => 'flash_alert flash' do a = @flash[:alert] if a.kind_of? Array ul do a.each do |t| li t end end else text a end end end end |
#to_html(opts = {}) ⇒ Object
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 |
# File 'lib/omf-web/theme/abstract_page.rb', line 116 def to_html(opts = {}) page_title = @page_title # context may get screwed up below, so put title into scope b = super if @opts[:request].params.key?('embedded') b else e = render_externals << render_additional_headers << render_data_sources r = Erector.inline do #instruct text! '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' html do head do title page_title || "OMF WEB" 'http-equiv' => "content-type", :content => "text/html; charset=UTF8" #<link rel="shortcut icon" href="/resource/theme/@theme/img/favicon.ico"> #<link rel="apple-touch-icon" href="/resource/theme/@theme/img/apple-touch-icon.png"> text! e.join("\n") end body do text! b end end end r.to_html(opts) end end |