From bef9dd8e678ce1c30c9e862b34be603a68dc24f3 Mon Sep 17 00:00:00 2001 From: did Date: Thu, 10 Nov 2011 13:41:20 -0800 Subject: [PATCH] fix various namespace errors issues and api changes for the models --- .../javascripts/locomotive/templates/.gitkeep | 0 app/assets/stylesheets/locomotive/simple.scss | 2 +- app/controllers/locomotive/base_controller.rb | 2 +- .../locomotive/installation_controller.rb | 6 +++-- .../locomotive/pages_controller.rb | 17 +++++++++----- app/helpers/locomotive/base_helper.rb | 9 ++++++++ app/helpers/locomotive/installation_helper.rb | 7 ++++++ app/models/locomotive/asset.rb | 6 ++--- app/models/locomotive/content_instance.rb | 4 ++-- app/models/locomotive/editable_element.rb | 2 +- app/models/locomotive/editable_file.rb | 2 +- app/models/locomotive/snippet.rb | 2 +- app/models/locomotive/theme_asset.rb | 2 +- app/uploaders/locomotive/asset_uploader.rb | 2 +- .../locomotive/theme_asset_uploader.rb | 2 +- .../locomotive/installation/step_1.html.haml | 2 +- app/views/locomotive/pages/_form.html.haml | 2 +- lib/locomotive/core_ext.rb | 22 +++++++++++++++++-- lib/locomotive/responder.rb | 22 +++++++++++++++++++ 19 files changed, 88 insertions(+), 25 deletions(-) delete mode 100644 app/assets/javascripts/locomotive/templates/.gitkeep create mode 100644 app/helpers/locomotive/installation_helper.rb diff --git a/app/assets/javascripts/locomotive/templates/.gitkeep b/app/assets/javascripts/locomotive/templates/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/assets/stylesheets/locomotive/simple.scss b/app/assets/stylesheets/locomotive/simple.scss index 1f749978..2cf46555 100644 --- a/app/assets/stylesheets/locomotive/simple.scss +++ b/app/assets/stylesheets/locomotive/simple.scss @@ -157,7 +157,7 @@ div#flash-notice { text-align: right; - input[type=submit] { + input[type=submit], a.button { @include black-button; margin: 0 18px 0 0; diff --git a/app/controllers/locomotive/base_controller.rb b/app/controllers/locomotive/base_controller.rb index 4876dbb3..632802c1 100644 --- a/app/controllers/locomotive/base_controller.rb +++ b/app/controllers/locomotive/base_controller.rb @@ -17,7 +17,7 @@ module Locomotive before_filter :set_current_thread_variables - helper_method :sections, :current_site_url, :site_url, :page_url, :current_ability + helper_method :sections, :current_site_url, :site_url, :public_page_url, :current_ability # https://rails.lighthouseapp.com/projects/8994/tickets/1905-apphelpers-within-plugin-not-being-mixed-in helper Locomotive::BaseHelper, Locomotive::ContentTypesHelper #, Locomotive::BoxHelper diff --git a/app/controllers/locomotive/installation_controller.rb b/app/controllers/locomotive/installation_controller.rb index 38f505e0..40045398 100644 --- a/app/controllers/locomotive/installation_controller.rb +++ b/app/controllers/locomotive/installation_controller.rb @@ -7,6 +7,8 @@ module Locomotive before_filter :allow_installation? + helper Locomotive::BaseHelper + def show request.get? ? self.handle_get : self.handle_post end @@ -62,9 +64,9 @@ module Locomotive def last_url if Locomotive.config.manage_domains? - session_url(:host => Site.first.domains.first, :port => request.port) + locomotive_account_session_url(:host => Site.first.domains.first, :port => request.port) else - session_url + locomotive_account_session_url end end diff --git a/app/controllers/locomotive/pages_controller.rb b/app/controllers/locomotive/pages_controller.rb index 69e6a303..3c60f808 100644 --- a/app/controllers/locomotive/pages_controller.rb +++ b/app/controllers/locomotive/pages_controller.rb @@ -16,15 +16,15 @@ module Locomotive end def create - @page = Page.create(params[:page]) - respond_with @page + @page = current_site.pages.create(params[:page]) + respond_with @page, :location => edit_page_url(@page._id) end def update - @page = Page.find(params[:id]) + @page = current_site.pages.find(params[:id]) @page.update_attributes(params[:page]) respond_with @page do |format| - format.html { redirect_to edit_page_url(@page) } + format.html { redirect_to edit_page_url(@page._id) } format.json do render :json => { :notice => t('flash.locomotive.pages.update.notice'), @@ -35,17 +35,22 @@ module Locomotive end end + def destroy + @page = current_site.pages.find(params[:id]) + @page.destroy + respond_with @page + end + def sort @page = current_site.pages.find(params[:id]) @page.sort_children!(params[:children]) - respond_with @page end def get_path page = current_site.pages.build(:parent => current_site.pages.find(params[:parent_id]), :slug => params[:slug].permalink) - render :json => { :url => page_url(page), :slug => page.slug } + render :json => { :url => public_page_url(page), :slug => page.slug } end end diff --git a/app/helpers/locomotive/base_helper.rb b/app/helpers/locomotive/base_helper.rb index 024f87db..8b85f2dc 100644 --- a/app/helpers/locomotive/base_helper.rb +++ b/app/helpers/locomotive/base_helper.rb @@ -83,4 +83,13 @@ module Locomotive::BaseHelper Locomotive.config.multi_sites? end + def public_page_url(page, options = {}) + if content = options.delete(:content) + File.join(current_site_url, page.fullpath.gsub('content_type_template', ''), content._slug) + else + File.join(current_site_url, page.fullpath) + end + end + + end diff --git a/app/helpers/locomotive/installation_helper.rb b/app/helpers/locomotive/installation_helper.rb new file mode 100644 index 00000000..5bda0a57 --- /dev/null +++ b/app/helpers/locomotive/installation_helper.rb @@ -0,0 +1,7 @@ +module Locomotive::InstallationHelper + + def next_installation_step_link(step = 1, label = nil) + link_to(content_tag(:span, label || t('admin.installation.common.next')), installation_step_url(step), :class => 'button') + end + +end diff --git a/app/models/locomotive/asset.rb b/app/models/locomotive/asset.rb index 12b390ed..91af46f5 100644 --- a/app/models/locomotive/asset.rb +++ b/app/models/locomotive/asset.rb @@ -1,8 +1,8 @@ module Locomotive class Asset - include Mongoid::Document - include Mongoid::Timestamps + include ::Mongoid::Document + include ::Mongoid::Timestamps ## extensions ## include Extensions::Asset::Types @@ -14,7 +14,7 @@ module Locomotive field :height, :type => Integer field :size, :type => Integer field :position, :type => Integer, :default => 0 - mount_uploader :source, AssetUploader + mount_uploader :source, AssetUploader, :mount_on => :source_filename ## associations ## referenced_in :site, :class_name => 'Locomotive::Site' diff --git a/app/models/locomotive/content_instance.rb b/app/models/locomotive/content_instance.rb index 327deb96..36f54f23 100644 --- a/app/models/locomotive/content_instance.rb +++ b/app/models/locomotive/content_instance.rb @@ -1,8 +1,8 @@ module Locomotive class ContentInstance - include Mongoid::Document - include Mongoid::Timestamps + include ::Mongoid::Document + include ::Mongoid::Timestamps ## extensions ## include CustomFields::ProxyClassEnabler diff --git a/app/models/locomotive/editable_element.rb b/app/models/locomotive/editable_element.rb index 8fb41d51..04cbc337 100644 --- a/app/models/locomotive/editable_element.rb +++ b/app/models/locomotive/editable_element.rb @@ -1,7 +1,7 @@ module Locomotive class EditableElement - include Mongoid::Document + include ::Mongoid::Document ## fields ## field :slug diff --git a/app/models/locomotive/editable_file.rb b/app/models/locomotive/editable_file.rb index a92a0e6c..8946ee2a 100644 --- a/app/models/locomotive/editable_file.rb +++ b/app/models/locomotive/editable_file.rb @@ -1,7 +1,7 @@ module Locomotive class EditableFile < EditableElement - mount_uploader :source, EditableFileUploader + mount_uploader :source, EditableFileUploader, :mount_on => :source_filename def content self.source? ? self.source.url : self.default_content diff --git a/app/models/locomotive/snippet.rb b/app/models/locomotive/snippet.rb index 2f6ec767..75003f23 100644 --- a/app/models/locomotive/snippet.rb +++ b/app/models/locomotive/snippet.rb @@ -1,4 +1,4 @@ -module +module Locomotive class Snippet include Locomotive::Mongoid::Document diff --git a/app/models/locomotive/theme_asset.rb b/app/models/locomotive/theme_asset.rb index 15333f42..78f6e40f 100644 --- a/app/models/locomotive/theme_asset.rb +++ b/app/models/locomotive/theme_asset.rb @@ -13,7 +13,7 @@ module Locomotive field :height, :type => Integer field :size, :type => Integer field :folder, :default => nil - mount_uploader :source, ThemeAssetUploader + mount_uploader :source, ThemeAssetUploader, :mount_on => :source_filename ## associations ## referenced_in :site, :class_name => 'Locomotive::Site' diff --git a/app/uploaders/locomotive/asset_uploader.rb b/app/uploaders/locomotive/asset_uploader.rb index b2a8da72..320fd5f4 100644 --- a/app/uploaders/locomotive/asset_uploader.rb +++ b/app/uploaders/locomotive/asset_uploader.rb @@ -1,7 +1,7 @@ # encoding: utf-8 module Locomotive - class AssetUploader < CarrierWave::Uploader::Base + class AssetUploader < ::CarrierWave::Uploader::Base include Locomotive::CarrierWave::Uploader::Asset diff --git a/app/uploaders/locomotive/theme_asset_uploader.rb b/app/uploaders/locomotive/theme_asset_uploader.rb index 80e838e3..c549dcd1 100644 --- a/app/uploaders/locomotive/theme_asset_uploader.rb +++ b/app/uploaders/locomotive/theme_asset_uploader.rb @@ -1,7 +1,7 @@ # encoding: utf-8 module Locomotive - class ThemeAssetUploader < CarrierWave::Uploader::Base + class ThemeAssetUploader < ::CarrierWave::Uploader::Base include Locomotive::CarrierWave::Uploader::Asset diff --git a/app/views/locomotive/installation/step_1.html.haml b/app/views/locomotive/installation/step_1.html.haml index 89e01e5f..cccb6ad5 100644 --- a/app/views/locomotive/installation/step_1.html.haml +++ b/app/views/locomotive/installation/step_1.html.haml @@ -2,7 +2,7 @@ = t('locomotive.installation.common.title') - content_for :head do - = stylesheet_link_tag 'locomotive_installation', :media => 'screen' + = stylesheet_link_tag 'locomotive/installation', :media => 'screen' - title t('.title') diff --git a/app/views/locomotive/pages/_form.html.haml b/app/views/locomotive/pages/_form.html.haml index b21130b3..3054c7b7 100644 --- a/app/views/locomotive/pages/_form.html.haml +++ b/app/views/locomotive/pages/_form.html.haml @@ -7,7 +7,7 @@ - if not @page.index? and not @page.not_found? = f.input :parent_id, :as => :select, :collection => parent_pages_options, :include_blank => false - = f.input :slug, :required => false, :hint => @page.slug.blank? ? t('.empty_slug') : page_url(@page), :input_html => { :'data-url' => get_path_pages_url, :disabled => @page.index? || @page.not_found? }, :wrapper_html => { :style => "#{'display: none' if @page.templatized?};" } + = f.input :slug, :required => false, :hint => @page.slug.blank? ? t('.empty_slug') : public_page_url(@page), :input_html => { :'data-url' => get_path_pages_url, :disabled => @page.index? || @page.not_found? }, :wrapper_html => { :style => "#{'display: none' if @page.templatized?};" } = render 'editable_elements', :page => @page diff --git a/lib/locomotive/core_ext.rb b/lib/locomotive/core_ext.rb index 817657b5..ca911d2b 100644 --- a/lib/locomotive/core_ext.rb +++ b/lib/locomotive/core_ext.rb @@ -1,5 +1,8 @@ +# encoding: utf-8 + ## String -class String + +class String #:nodoc def permalink self.parameterize('-') @@ -15,7 +18,7 @@ end ## Hash -class Hash +class Hash #:nodoc def underscore_keys new_hash = {} @@ -43,4 +46,19 @@ class Hash end +class Boolean #:nodoc + BOOLEAN_MAP = { + true => true, "true" => true, "TRUE" => true, "1" => true, 1 => true, 1.0 => true, + false => false, "false" => false, "FALSE" => false, "0" => false, 0 => false, 0.0 => false + } + + def self.set(value) + value = BOOLEAN_MAP[value] + value.nil? ? nil : value + end + + def self.get(value) + value + end +end diff --git a/lib/locomotive/responder.rb b/lib/locomotive/responder.rb index 7fc50fd4..59d23518 100644 --- a/lib/locomotive/responder.rb +++ b/lib/locomotive/responder.rb @@ -8,6 +8,28 @@ module Locomotive super || has_errors? end + def api_behavior(error) + puts "api_behavior here" + + super + + puts "api_behavior there" + end + + # def api_behavior(error) + # raise error unless resourceful? + # + # if get? + # display resource + # elsif post? + # display resource, :status => :created, :location => api_location + # elsif has_empty_resource_definition? + # display empty_resource, :status => :ok + # else + # head :ok + # end + # end + def to_json if get? display resource