Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Namespace Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
peterberkenbosch authored and LBRapid committed Dec 12, 2011
1 parent 282e61e commit 0627983
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 131 deletions.
33 changes: 13 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
#require 'cucumber/rake/task'
require 'spree_core/testing_support/common_rake'
# encoding: utf-8
require 'bundler'
Bundler::GemHelper.install_tasks
Bundler.setup

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new
#Cucumber::Rake::Task.new

# task :default => [:spec, :cucumber ]
task :default => [:spec]
require 'spree/core/testing_support/common_rake'

spec = eval(File.read('spree_static_content.gemspec'))

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
desc "Default Task"
task :default => [ :spec ]

desc "Release to gemcutter"
task :release => :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
namespace :test_app do
desc 'Rebuild test and cucumber databases'
task :rebuild_dbs do
system("cd spec/test_app && rake db:drop db:migrate RAILS_ENV=test && rake db:drop db:migrate RAILS_ENV=cucumber")
end
end

desc "Generates a dummy app for testing"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.70.3
1.0.0.beta
1 change: 1 addition & 0 deletions Versionfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"1.0.0.x" => { :version => '1.0.0.beta', :ref => '02f368e6a371554c50b07ac0ef4ff06d735fbbb6' }
"0.70.x" => { :version => '0.70.3', :ref => '1861f4cd08c0ffa9940f0c81e69ea29b4541dbbd' }
"0.60.x" => { :tag => "v0.60.2", :version => '0.60.2'}
"0.50.x" => { :version => '0.40.2', :ref => '45b0050b96809c8fb0f21940f9407e9012a6d420' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class Admin::PagesController < Admin::ResourceController
class Spree::Admin::PagesController < Spree::Admin::ResourceController
update.after :expire_cache

def new
@page = @object
end

def edit
@page = @object
end

private
def expire_cache
expire_page :controller => '/static_content', :action => 'show', :path => @object.slug
Expand Down
33 changes: 0 additions & 33 deletions app/controllers/spree/base_controller_decorator.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class StaticContentController < Spree::BaseController
class Spree::StaticContentController < Spree::BaseController
caches_action :show

def show
path = case params[:path]
when Array
'/' + params[:path].join("/")
when String
params[:path]
'/' + params[:path]
when nil
request.path
end

unless @page = Page.visible.find_by_slug(path)
unless @page = Spree::Page.visible.find_by_slug(path)
render_404
end
end

private

def accurate_title
@page ? (@page.meta_title ? @page.meta_title : @page.title) : nil
end
Expand Down
20 changes: 10 additions & 10 deletions app/models/page.rb → app/models/spree/page.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
class Page < ActiveRecord::Base
class Spree::Page < ActiveRecord::Base
default_scope :order => "position ASC"

validates_presence_of :title
validates_presence_of [:slug, :body], :if => :not_using_foreign_link?

scope :visible, where(:visible => true)
scope :header_links, where(:show_in_header => true).visible
scope :footer_links, where(:show_in_footer => true).visible
scope :sidebar_links, where(:show_in_sidebar => true).visible


before_save :update_positions_and_slug

def initialize(*args)
super(*args)
last_page = Page.last
last_page = Spree::Page.last
self.position = last_page ? last_page.position + 1 : 0
end

Expand All @@ -26,11 +26,11 @@ def link

def update_positions_and_slug
unless new_record?
return unless prev_position = Page.find(self.id).position
return unless prev_position = Spree::Page.find(self.id).position
if prev_position > self.position
Page.update_all("position = position + 1", ["? <= position AND position < ?", self.position, prev_position])
Spree::Page.update_all("position = position + 1", ["? <= position AND position < ?", self.position, prev_position])
elsif prev_position < self.position
Page.update_all("position = position - 1", ["? < position AND position <= ?", prev_position, self.position])
Spree::Page.update_all("position = position - 1", ["? < position AND position <= ?", prev_position, self.position])
end
end

Expand All @@ -40,15 +40,15 @@ def update_positions_and_slug
end
return true
end

def not_using_foreign_link?
foreign_link.blank?
end

def slug_link
ensure_slash_prefix slug
end

def ensure_slash_prefix(str)
str.index('/') == 0 ? str : '/' + str
end
Expand Down
2 changes: 1 addition & 1 deletion app/overrides/static_content_admin_tab.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Deface::Override.new(:virtual_path => "layouts/admin",
Deface::Override.new(:virtual_path => "spree/layouts/admin",
:name => "static_content_admin_tab",
:insert_bottom => "[data-hook='admin_tabs']",
:text => "<%= tab(:pages) %>")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1><%= t("static_content.editing_page") %></h1>
<%= render "shared/error_messages", :target => @page %>
<%= render "spree/shared/error_messages", :target => @page %>
<%= semantic_form_for([:admin, @page]) do |f| -%>
<%= render :partial => "form", :locals => { :f => f } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

<table class="index">
<tr>
<th><%= Page.human_attribute_name(:title) %></th>
<th><%= Spree::Page.human_attribute_name(:title) %></th>
<th><%= t("static_content.link") %></th>
<th><%= Page.human_attribute_name(:visible) %></th>
<th><%= Spree::Page.human_attribute_name(:visible) %></th>
<th><%= t("action") %></th>
</tr>
<tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1><%= t("static_content.new_page") %></h1>
<%= render "shared/error_messages", :target => @page %>
<%= render "spree/shared/error_messages", :target => @page %>
<%= semantic_form_for([:admin, @page]) do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<% end -%>
<% content_for :sidebar do %>
<% if "products" == @current_controller && @taxon %>
<%= render :partial => "shared/filters" %>
<%= render :partial => "spree/shared/filters" %>
<% else %>
<%= render :partial => "shared/taxonomies" %>
<%= render :partial => "spree/shared/taxonomies" %>
<% end %>
<% end %>
<h1><%= @page.title %></h1>
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Rails.application.routes.draw do
Spree::Core::Engine.routes.append do

namespace :admin do
resources :pages
end

match '/static/*path', :to => 'static_content#show', :via => :get, :as => 'static'

match '/*path', :to => 'static_content#show', :via => :get, :as => 'static'

end
9 changes: 8 additions & 1 deletion db/migrate/20090625125735_extend_pages.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
class ExtendPages < ActiveRecord::Migration
class Page < ActiveRecord::Base
end

def self.up
change_table :pages do |t|
t.boolean :show_in_header, :default => false, :null => false
t.boolean :show_in_footer, :default => false, :null => false
t.string :foreign_link
t.integer :position, :default => 1, :null => false
Page.all(:order => "updated_at ASC").each_with_index{|page,x| page.update_attribute(:position, x+1)}
if Page.table_exists?
Page.all(:order => "updated_at ASC").each_with_index{|page,x| page.update_attribute(:position, x+1)}
else
Spree::Page.all(:order => "updated_at ASC").each_with_index{|page,x| page.update_attribute(:position, x+1)}
end

end
end
Expand Down
13 changes: 10 additions & 3 deletions db/migrate/20090814113100_add_visible_to_pages.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
class AddVisibleToPages < ActiveRecord::Migration
class Page < ActiveRecord::Base
end

def self.up
add_column :pages, :visible, :boolean
Page.update_all :visible => true
if Page.table_exists?
Page.update_all :visible => true
else
Spree::Page.update_all :visible => true
end
end

def self.down
remove_column :pages, :visible
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20111201184855_prefix_table_names.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PrefixTableNames < ActiveRecord::Migration
def change
rename_table :pages, :spree_pages
end
end
22 changes: 2 additions & 20 deletions lib/spree_static_content.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
require 'spree_core'
require 'spree/core'
require 'formtastic'

module SpreeStaticContent
class Engine < Rails::Engine
engine_name 'spree_static_content'

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/**/*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
end
config.to_prepare &method(:activate).to_proc
config.autoload_paths += %W(#{config.root}/lib)
end
end

require 'spree_static_content/engine'
17 changes: 17 additions & 0 deletions lib/spree_static_content/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SpreeStaticContent
class Engine < Rails::Engine
engine_name 'spree_static_content'

def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../../app/overrides/**/*.rb")) do |c|
Rails.application.config.cache_classes ? require(c) : load(c)
end
end
config.to_prepare &method(:activate).to_proc
config.autoload_paths += %W(#{config.root}/lib)
end
end
8 changes: 4 additions & 4 deletions spec/models/page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe Page do
describe Spree::Page do
before(:each) do
@page = Page.create(
@page = Spree::Page.create(
:title => 'test page',
:slug => 'test-page',
:body => 'this is a test page'
Expand All @@ -12,9 +12,9 @@
it "should be valid" do
@page.should be_valid
end

it "should add an / to the slug" do
@page.slug.should == "/test-page"
end

end
15 changes: 0 additions & 15 deletions spec/routing/content_controller_spec.rb

This file was deleted.

Loading

0 comments on commit 0627983

Please sign in to comment.