Permalink
Browse files

import of all files

  • Loading branch information...
1 parent 985f55d commit d2da69d82321f9c7a0de3aeaaa1e7766a29437f1 Seb Weston committed Jun 14, 2011
View
@@ -0,0 +1,9 @@
+\#*
+*~
+.#*
+.DS_Store
+.idea
+.project
+tmp
+nbproject
+*.swp
View
23 LICENSE
@@ -0,0 +1,23 @@
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Rails Dog LLC nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,19 @@
+Summary
+-------
+
+This is a really basic page CMS which fits neatly into the Spree Administration toolbar.
+
+I recommend that you also use Spree Editor and configure it to use pages_body:
+
+ https://github.com/spree/spree_editor
+
+Installation
+------------
+
+ gem "spree_pages", :git => 'git://github.com/sebastyuiop/spree_pages.git'
+
+ rake spree_pages:install
+
+ rake db:migrate
+
+Copyright (c) 2011 sebastyuiop, released under the New BSD License
View
@@ -0,0 +1,75 @@
+require 'rubygems'
+require 'rake'
+require 'rake/testtask'
+require 'rake/packagetask'
+require 'rake/gempackagetask'
+
+gemfile = File.expand_path('../spec/test_app/Gemfile', __FILE__)
+if File.exists?(gemfile) && (%w(spec cucumber).include?(ARGV.first.to_s) || ARGV.size == 0)
+ require 'bundler'
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ Bundler.setup
+
+ require 'rspec'
+ require 'rspec/core/rake_task'
+ RSpec::Core::RakeTask.new
+
+ require 'cucumber/rake/task'
+ Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = %w{--format progress}
+ end
+end
+
+desc "Default Task"
+task :default => [:spec, :cucumber ]
+
+spec = eval(File.read('spree_pages.gemspec'))
+
+Rake::GemPackageTask.new(spec) do |p|
+ p.gem_spec = spec
+end
+
+desc "Release to gemcutter"
+task :release => :package do
+ require 'rake/gemcutter'
+ Rake::Gemcutter::Tasks.new(spec).define
+ Rake::Task['gem:push'].invoke
+end
+
+desc "Default Task"
+task :default => [ :spec ]
+
+desc "Regenerates a rails 3 app for testing"
+task :test_app do
+ require '../spree/lib/generators/spree/test_app_generator'
+ class SpreePageTestAppGenerator < Spree::Generators::TestAppGenerator
+
+ def install_gems
+ inside "test_app" do
+ run 'rake spree_core:install'
+ run 'rake spree_pages:install'
+ end
+ end
+
+ def migrate_db
+ run_migrations
+ end
+
+ protected
+ def full_path_for_local_gems
+ <<-gems
+gem 'spree_core', :path => \'#{File.join(File.dirname(__FILE__), "../spree/", "core")}\'
+gem 'spree_pages', :path => \'#{File.dirname(__FILE__)}\'
+ gems
+ end
+
+ end
+ SpreePageTestAppGenerator.start
+end
+
+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
View
@@ -0,0 +1,2 @@
+"0.60.x" => { :branch => "master" }
+# "0.50.x" NOT TESTED
@@ -0,0 +1,45 @@
+class Admin::PagesController < Admin::ResourceController
+
+ def index
+ @pages = Page.paginate(:per_page => 50, :page => params[:page])
+ end
+
+ def show
+ @page = Page.find(params[:id])
+ end
+
+ def new
+ @page = Page.new
+ end
+
+ def create
+ @page = Page.new(params[:page])
+ if @page.save
+ flash[:notice] = "Successfully created page."
+ redirect_to admin_pages_url
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @page = Page.find(params[:id])
+ end
+
+ def update
+ @page = Page.find(params[:id])
+ if @page.update_attributes(params[:page])
+ flash[:notice] = "Successfully updated page."
+ redirect_to admin_pages_url
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @page = Page.find(params[:id])
+ @page.destroy
+ flash[:notice] = "Successfully destroyed page."
+ redirect_to admin_pages_url
+ end
+end
@@ -0,0 +1,12 @@
+class PagesController < Spree::BaseController
+
+ # GET /pages/about-us
+ def show
+ @page = Page.where(:published => true, :permalink => params[:id]).first
+
+ respond_to do |format|
+ format.html # show.html.erb
+ end
+ end
+
+end
View
@@ -0,0 +1,6 @@
+class Page < ActiveRecord::Base
+ validates :title, :presence => true
+ validates :permalink, :uniqueness => true
+
+ scope :published, where(:published => true)
+end
@@ -0,0 +1,26 @@
+<%- locals = {:f => f} %>
+<%= hook :admin_page_form_fields, locals do %>
+ <%= f.field_container :title do %>
+ <%= f.label :title, t("title") %><br />
+ <%= f.text_field :title %>
+ <%= error_message_on :page, :title %>
+ <% end %>
+
+ <%= f.field_container :body do %>
+ <%= f.label :body, t("body") %><br />
+ <%= f.text_area :body %>
+ <%= error_message_on :page, :body %>
+ <% end %>
+
+ <%= f.field_container :permalink do %>
+ <%= f.label :permalink, t("permalink") %><br />
+ <%= f.text_field :permalink %>
+ <%= error_message_on :page, :permalink %>
+ <% end %>
+
+ <%= f.field_container :published do %>
+ <%= f.label :published, t("published") %><br />
+ <%= f.check_box :published %>
+ <%= error_message_on :page, :published %>
+ <% end %>
+<% end %>
@@ -0,0 +1,14 @@
+<%= hook :admin_page_edit_form_header do %>
+ <%= render 'shared/error_messages', :target => @page %>
+ <h1><%= t("editing_page") %></h1>
+<% end %>
+
+<%= hook :admin_page_edit_form do %>
+ <%= form_for(:page, :url => object_url, :html => { :method => :put }) do |f| %>
+ <%= render :partial => "form", :locals => { :f => f } %>
+
+ <%= hook :admin_page_edit_form_buttons do %>
+ <%= render :partial => "admin/shared/edit_resource_links" %>
+ <% end %>
+ <% end %>
+<% end %>
@@ -0,0 +1,32 @@
+<div class='toolbar'>
+ <ul class='actions'>
+ <li>
+ <p><%= button_link_to t("new_page"), new_object_url, :icon => 'add' %></p>
+ </li>
+ </ul>
+ <br class='clear' />
+</div>
+
+<h1><%= t("listing_pages") %></h1>
+
+<table class="index">
+ <thead>
+ <tr>
+ <th><%= t("page_title") %></th>
+ <th>&nbsp;</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @pages.each do |page|%>
+ <tr id="<%= dom_id page %>">
+ <td width="350px"><%=link_to page.title, edit_object_url(page) %></td>
+ <td>
+ <%= link_to_edit page %> &nbsp;
+ <%= link_to_delete page %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<%= will_paginate(:previous_label => "&#171; #{t('previous')}", :next_label => "#{t('next')} &#187;") %>
@@ -0,0 +1,14 @@
+<%= hook :admin_page_new_form_header do %>
+ <%= render 'shared/error_messages', :target => @page %>
+ <h1><%= t("new_page") %></h1>
+<% end %>
+
+<%= hook :admin_page_new_form do %>
+ <%= form_for(:page, :url => collection_url) do |f| %>
+ <%= render :partial => "form", :locals => { :f => f } %>
+
+ <%= hook :admin_page_new_form_buttons do %>
+ <%= render :partial => "admin/shared/new_resource_links" %>
+ <% end %>
+ <% end %>
+<% end %>
@@ -0,0 +1,6 @@
+<% @body_id = 'page-show' %>
+<h1><%= @page.title %></h1>
+
+<div id="page-body">
+ <%= @page.body %>
+</div>
@@ -0,0 +1,11 @@
+---
+en:
+ pages: "Pages"
+ new_page: "New Page"
+ listing_pages: "Listing Pages"
+ title: "Title"
+ body: "Body"
+ permalink: "Permalink"
+ published: "Published"
+ editing_page: "Editing Page"
+ page_title: "Page Title"
View
@@ -0,0 +1,7 @@
+Rails.application.routes.draw do
+ resources :pages
+
+ namespace :admin do
+ resources :pages
+ end
+end
@@ -0,0 +1,15 @@
+class CreatePages < ActiveRecord::Migration
+ def self.up
+ create_table :pages do |t|
+ t.string :title
+ t.text :body
+ t.string :permalink
+ t.boolean :published
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :pages
+ end
+end
View
@@ -0,0 +1,17 @@
+require 'spree_core'
+require 'spree_pages_hooks'
+
+module SpreePages
+ class Engine < Rails::Engine
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
+ Rails.env.production? ? require(c) : load(c)
+ end
+ end
+
+ config.to_prepare &method(:activate).to_proc
+ end
+end
View
@@ -0,0 +1,5 @@
+class SpreePagesHooks < Spree::ThemeSupport::HookListener
+ insert_after :admin_tabs do
+ %(<%= tab(:pages) %>)
+ end
+end
View
@@ -0,0 +1,25 @@
+namespace :spree_pages do
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
+ task :install do
+ Rake::Task['spree_pages:install:migrations'].invoke
+ Rake::Task['spree_pages:install:assets'].invoke
+ end
+
+ namespace :install do
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
+ task :migrations do
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
+ destination = File.join(Rails.root, 'db')
+ Spree::FileUtilz.mirror_files(source, destination)
+ end
+
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
+ task :assets do
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
+ destination = File.join(Rails.root, 'public')
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
+ Spree::FileUtilz.mirror_files(source, destination)
+ end
+ end
+
+end
@@ -0,0 +1 @@
+# add custom rake tasks here
Oops, something went wrong.

0 comments on commit d2da69d

Please sign in to comment.