Class: Olelo::Application

Inherits:
Object show all
Includes:
ApplicationHelper, ErrorHandler, Hooks, Routing, Util
Defined in:
lib/olelo/application.rb

Overview

Main class of the application

Instance Attribute Summary collapse

Attributes included from Routing

#env, #original_params, #params, #request, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

#action?, #build_static_path, #footer, #head, #menu, #render, #render_partial, #session, #tabs, #title

Methods included from Templates

enable_caching, #render, with_caching

Methods included from HttpHelper

#cache_control

Methods included from Util

#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?

Methods included from PageHelper

#breadcrumbs, #build_path, #date, #format_diff, #include_page, #pagination, #render_page

Methods included from FlashHelper

#flash, #flash_messages

Methods included from BlockHelper

#blocks, #define_block, #include_block, #render_block, #wrap_block

Methods included from Routing

#call, #call!, #forward, #halt, included, #pass, #redirect

Methods included from ErrorHandler

#handle_error, included

Methods included from Hooks

included, #invoke_hook, #with_hooks

Constructor Details

#initialize(app = nil) ⇒ Application

Returns a new instance of Application.



28
29
30
# File 'lib/olelo/application.rb', line 28

def initialize(app = nil)
  @app = app
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



11
12
13
# File 'lib/olelo/application.rb', line 11

def page
  @page
end

Class Method Details

.reserved_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
# File 'lib/olelo/application.rb', line 18

def self.reserved_path?(path)
  path = '/' + path.cleanpath
  path.starts_with?('/static') ||
  router.any? do |method, r|
    r.any? do |name,pattern,keys,function|
      name !~ /^\/\(?:path\)?$/ && pattern.match(path)
    end
  end
end

Instance Method Details

#post_attributesObject



201
202
203
204
205
206
207
208
209
210
# File 'lib/olelo/application.rb', line 201

def post_attributes
  page.update_attributes(params)
  redirect build_path(page.path) if @close && !page.modified?
  check do |errors|
    errors << :version_conflict.t if !page.new? && page.version.to_s != params[:version]
    errors << :no_changes.t if !page.modified?
  end
  page.save
  Page.commit(:attributes_edited.t(page: page.title))
end

#post_editObject



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/olelo/application.rb', line 166

def post_edit
  raise 'No content' if !params[:content]
  params[:content].gsub!("\r\n", "\n")
  message = :page_edited.t(page: page.title)
  message << " - #{params[:comment]}" if !params[:comment].blank?

  page.content = if params[:pos]
                   [page.content[0, params[:pos].to_i].to_s,
                    params[:content],
                    page.content[params[:pos].to_i + params[:len].to_i .. -1]].join
                 else
                   params[:content]
                 end
  redirect build_path(page.path) if @close && !page.modified?
  check do |errors|
    errors << :version_conflict.t if !page.new? && page.version.to_s != params[:version]
    errors << :no_changes.t if !page.modified?
  end
  page.save

  Page.commit(message)
  params.delete(:comment)
end

#post_uploadObject



190
191
192
193
194
195
196
197
198
199
# File 'lib/olelo/application.rb', line 190

def post_upload
  raise 'No file' if !params[:file]
  page.content = params[:file][:tempfile].read
  check do |errors|
    errors << :version_conflict.t if !page.new? && page.version.to_s != params[:version]
    errors << :no_changes.t if !page.modified?
  end
  page.save
  Page.commit(:page_uploaded.t(page: page.title))
end

#show_pageObject



212
213
214
# File 'lib/olelo/application.rb', line 212

def show_page
  render(:show, locals: {content: page.try(:content)})
end