Class: Olelo::Application
- Includes:
- ApplicationHelper, ErrorHandler, Hooks, Routing, Util
- Defined in:
- lib/olelo/application.rb
Overview
Main class of the application
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Attributes included from Routing
#env, #original_params, #params, #request, #response
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app = nil) ⇒ Application
constructor
A new instance of Application.
- #post_attributes ⇒ Object
- #post_edit ⇒ Object
- #post_upload ⇒ Object
- #show_page ⇒ Object
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
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
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
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
#page ⇒ Object (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
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_attributes ⇒ Object
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_edit ⇒ Object
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") = :page_edited.t(page: page.title) << " - #{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() params.delete(:comment) end |
#post_upload ⇒ Object
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_page ⇒ Object
212 213 214 |
# File 'lib/olelo/application.rb', line 212 def show_page render(:show, locals: {content: page.try(:content)}) end |