Module: HtmlGrid::DojoToolkit::DojoTemplate

Defined in:
lib/htmlgrid/dojotoolkit.rb

Constant Summary collapse

DOJO_DEBUG =
false
DOJO_BACK_BUTTON =
false
DOJO_ENCODING =
nil
DOJO_PARSE_WIDGETS =
true
DOJO_PREFIX =
[]
DOJO_REQUIRE =
[]

Instance Method Summary collapse

Instance Method Details

#dojo_parse_widgetsObject



168
169
170
# File 'lib/htmlgrid/dojotoolkit.rb', line 168

def dojo_parse_widgets
  self.class::DOJO_PARSE_WIDGETS
end

#dynamic_html_headers(context) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/htmlgrid/dojotoolkit.rb', line 93

def dynamic_html_headers(context)
  headers = super
  encoding = self.class::DOJO_ENCODING
  encoding ||= if RUBY_VERSION >= '1.9'
                 Encoding.default_external
               else
                 $KCODE == 'UTF8' ? 'UTF-8' : 'ISO-8859-1'
               end
  dojo_path = @lookandfeel.resource_global(:dojo_js)
  dojo_path ||= '/resources/dojo/dojo/dojo.js'
  args = { 'type' => 'text/javascript'}
  headers << context.script(args.dup) {
    "djConfig = {
      isDebug:              #{self.class::DOJO_DEBUG},
      parseWidgets:         #{dojo_parse_widgets},
      preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON},
      bindEncoding:         '#{encoding}',
      searchIds:            [],
      urchin:               ''
    };"
  }
  packages = ""
  unless(self.class::DOJO_PREFIX.empty?)
    packages = self.class::DOJO_PREFIX.collect { |prefix, path|
      "{ name: '#{prefix}', location: '#{path}' }"
    }.join(",")
  end
  config = [
    "parseOnLoad:          true",
    "isDebug:              #{self.class::DOJO_DEBUG}",
    "preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON}",
    "bindEncoding:         '#{encoding}'",
    "searchIds:            []",
    "async:                true",
    "urchin:               ''",
    "has: {
       'dojo-firebug':        #{self.class::DOJO_DEBUG},
       'dojo-debug-messages': #{self.class::DOJO_DEBUG}
    }",
    "packages: [ #{packages} ]"
  ].join(',')
  args.store('data-dojo-config', config)
  args.store('src', dojo_path)

  headers << context.script(args)
  args = { 'type' => 'text/javascript' }
  headers << context.script(args) {
    script = ''
    self.class::DOJO_REQUIRE.each { |req|
      script << "'#{req}',"
    }
    if(@dojo_onloads)
      onloads = ''
      @dojo_onloads.each { |onload|
        onloads << "#{onload}\n"
      }
      script =
      "require([#{script.chomp(',')}], function(ready, parser) {" \
        "ready(function() {" \
          "#{onloads}" \
        "});" \
      "});"
    else
      script = "require([#{script.chomp(',')}]);"
    end
    script
  }
  dojo_dir = File.dirname(dojo_path)
  headers << context.style(:type => "text/css") { "      @import \"\#{File.join(dojo_dir, \"/resources/dojo.css\")}\";\n      @import \"\#{File.join(dojo_dir, \"../dijit/themes/tundra/tundra.css\")}\";\n    EOS\n  }\n  headers\nend\n"

#onload=(script) ⇒ Object



171
172
173
# File 'lib/htmlgrid/dojotoolkit.rb', line 171

def onload=(script)
  (@dojo_onloads ||= []).push(script)
end