Sha256: 80c59b381adbaaffb500d41781a566ef660e3a3ae9b965e1894fb85f7e19b531

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

description  'Export variables to context and javascript'
dependencies 'aspects'

def self.exported_global_variables
  {
    'base_path'             => Config['base_path'],
    'default_mime'          => Page.default_mime
  }
end

def self.exported_page_variables(page)
  {
    'page_name'             => page.name,
    'page_new'              => page.new?,
    'page_modified'         => page.modified?,
    'page_path'             => page.path,
    'page_title'            => page.title,
    'page_version'          => page.version.to_s,
    'page_next_version'     => page.next_version.to_s,
    'page_previous_version' => page.previous_version.to_s,
    'page_mime'             => page.mime.to_s
  }
end

# Export variables to aspect context
Aspects::Context.hook(:initialized) do
  params.merge!(PLUGIN.exported_global_variables)
  params.merge!(PLUGIN.exported_page_variables(page))
end

# Export variables to javascript for client extensions
Application.hook :head, 1 do
  vars = params.merge(PLUGIN.exported_global_variables)
  if page
    vars.merge!(cache(['variables', page.path, page.etag], update: no_cache?, defer: true) do
      PLUGIN.exported_page_variables(page)
    end)
  end
  vars = vars.merge('user_name' => User.current.name) if User.logged_in?
  %{<script type="text/javascript">Olelo = #{escape_javascript MultiJson.dump(vars)};</script>}
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
olelo-0.9.15 plugins/misc/variables.rb
olelo-0.9.14 plugins/misc/variables.rb
olelo-0.9.13 plugins/misc/variables.rb
olelo-0.9.12 plugins/misc/variables.rb
olelo-0.9.11 plugins/misc/variables.rb