simple-pages-rails 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +22 -4
  3. data/Guardfile +47 -0
  4. data/app/assets/javascripts/simple_pages/application.js +0 -2
  5. data/app/assets/javascripts/simple_pages/pages.js.coffee +4 -0
  6. data/app/controllers/simple_pages/application_controller.rb +5 -4
  7. data/app/controllers/simple_pages/pages_controller.rb +6 -1
  8. data/app/helpers/simple_pages/application_helper.rb +0 -3
  9. data/app/helpers/simple_pages/pages_helper.rb +1 -1
  10. data/app/models/simple_pages/page.rb +6 -17
  11. data/lib/generators/simple_pages/USAGE +11 -0
  12. data/lib/generators/simple_pages/install_generator.rb +40 -0
  13. data/lib/generators/simple_pages/templates/cancan_ext.rb +25 -0
  14. data/lib/generators/simple_pages/templates/devise_ext.rb +25 -0
  15. data/lib/generators/simple_pages/templates/simple_pages.rb +19 -0
  16. data/lib/simple-pages-rails/version.rb +1 -1
  17. data/lib/simple_pages.rb +22 -11
  18. data/lib/simple_pages/controllers/page_layout_at.rb +34 -0
  19. data/lib/simple_pages/engine.rb +12 -0
  20. data/lib/simple_pages/models/page_attachment.rb +15 -0
  21. data/lib/simple_pages/models/page_author.rb +19 -0
  22. data/lib/simple_pages/models/page_locale.rb +28 -0
  23. data/lib/simple_pages/models/page_owner.rb +23 -0
  24. data/simple-pages-rails.gemspec +9 -1
  25. data/spec/configuration_spec.rb +39 -0
  26. data/spec/dummy/.rspec +1 -0
  27. data/spec/dummy/app/models/ability.rb +7 -0
  28. data/spec/dummy/app/models/user.rb +17 -0
  29. data/spec/dummy/config/environments/development.rb +2 -0
  30. data/spec/dummy/config/initializers/devise.rb +232 -0
  31. data/spec/dummy/config/initializers/simple_form.rb +142 -0
  32. data/spec/dummy/config/initializers/simple_form_bootstrap.rb +45 -0
  33. data/spec/dummy/config/initializers/simple_pages.rb +19 -0
  34. data/spec/dummy/config/locales/devise.en.yml +58 -0
  35. data/spec/dummy/config/locales/simple_form.en.yml +26 -0
  36. data/spec/dummy/config/routes.rb +3 -2
  37. data/spec/dummy/db/migrate/20121214105317_devise_create_users.rb +46 -0
  38. data/spec/dummy/db/migrate/20121214105802_create_simple_pages.simple_pages.rb +19 -0
  39. data/spec/dummy/db/schema.rb +51 -0
  40. data/spec/dummy/lib/cancan_ext.rb +25 -0
  41. data/spec/dummy/lib/devise_ext.rb +25 -0
  42. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  43. data/spec/spec_helper.rb +54 -0
  44. metadata +193 -8
  45. data/lib/simple_pages/page_author.rb +0 -17
  46. data/lib/simple_pages/page_layout_at.rb +0 -32
  47. data/spec/dummy/README.rdoc +0 -261
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ spec/dummy/db/*.sqlite3
6
6
  spec/dummy/log/*.log
7
7
  spec/dummy/tmp/
8
8
  spec/dummy/.sass-cache
9
+ tmp
data/Gemfile CHANGED
@@ -1,13 +1,10 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Declare your gem's dependencies in simple_pages.gemspec.
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
5
5
  # development dependencies will be added by default to the :development group.
6
6
  gemspec
7
7
 
8
- # jquery-rails is used by the dummy application
9
- gem "jquery-rails"
10
-
11
8
  # Declare any dependencies that are still in development here instead of in
12
9
  # your gemspec. These might include edge Rails or gems from your path or
13
10
  # Git. Remember to move these dependencies to your gemspec before releasing
@@ -15,3 +12,24 @@ gem "jquery-rails"
15
12
 
16
13
  # To use debugger
17
14
  # gem 'debugger'
15
+
16
+ # gems used by the dummy application
17
+ gem 'sass-rails', '~> 3.2.3'
18
+ gem 'coffee-rails', '~> 3.2.1'
19
+
20
+ gem 'devise'
21
+ gem 'cancan'
22
+ gem 'simple_form'
23
+ gem 'anjlab-bootstrap-rails', require: 'bootstrap-rails'
24
+
25
+ group :test do
26
+ if RUBY_PLATFORM =~ /darwin/i
27
+ gem 'rb-fsevent', '~> 0.9.1'
28
+ gem 'growl'
29
+ end
30
+
31
+ if RUBY_PLATFORM =~ /linux/i
32
+ gem 'rb-inotify'
33
+ gem 'libnotify'
34
+ end
35
+ end
data/Guardfile ADDED
@@ -0,0 +1,47 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'spork', cucumber_env: { 'RAILS_ENV' => 'test' }, rspec_env: { 'RAILS_ENV' => 'test' } do
5
+ watch('config/application.rb')
6
+ watch('config/environment.rb')
7
+ watch('config/environments/test.rb')
8
+ watch(%r{^config/initializers/.+\.rb$})
9
+ watch('Gemfile')
10
+ watch('Gemfile.lock')
11
+ watch('spec/spec_helper.rb') { :rspec }
12
+ watch('test/test_helper.rb') { :test_unit }
13
+ watch(%r{features/support/}) { :cucumber }
14
+ end
15
+
16
+ guard 'rspec', cli: '--color --drb' do
17
+ watch(%r{^spec/.+_spec\.rb$})
18
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
19
+ watch('spec/spec_helper.rb') { 'spec' }
20
+
21
+ # Rails example
22
+ watch(%r{^spec/dummy/app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
23
+ watch(%r{^spec/dummy/app/(.*)(\.erb|\.haml)$}) { |m|
24
+ "spec/#{m[1]}#{m[2]}_spec.rb"
25
+ }
26
+ watch(%r{^spec/dummy/app/controllers/(.+)_(controller)\.rb$}) { |m|
27
+ [
28
+ "spec/routing/#{m[1]}_routing_spec.rb",
29
+ "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
30
+ "spec/acceptance/#{m[1]}_spec.rb"
31
+ ]
32
+ }
33
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
34
+ watch('spec/dummy/config/routes.rb') { 'spec/routing' }
35
+ watch('spec/dummy/app/controllers/application_controller.rb') { 'spec/controllers' }
36
+
37
+ # Capybara features specs
38
+ watch(%r{^spec/dummy/app/views/(.+)/.*\.(erb|haml)$}) { |m|
39
+ "spec/features/#{m[1]}_spec.rb"
40
+ }
41
+
42
+ # Turnip features and steps
43
+ watch(%r{^spec/acceptance/(.+)\.feature$})
44
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m|
45
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
46
+ }
47
+ end
@@ -12,8 +12,6 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
- //= require jquery
16
- //= require jquery_ujs
17
15
  //= require twitter/bootstrap
18
16
  //= require chosen-jquery
19
17
  //= require ckeditor-jquery
@@ -0,0 +1,4 @@
1
+ $ ->
2
+ $('.pages .chzn-select').chosen
3
+ allow_single_deselect: true
4
+ no_results_text: 'No results matched'
@@ -1,11 +1,12 @@
1
1
  module SimplePages
2
2
  class ApplicationController < ActionController::Base
3
- include SimplePages::PageLayoutAt
4
-
5
3
  respond_to :html
6
4
 
7
- SimplePages.application_controller_modules.each do |module_name|
8
- include module_name
5
+ helper ::RailsTheme::Engine.helpers
6
+ helper SimplePages.helper_modules
7
+
8
+ SimplePages.controller_modules.each do |module_class|
9
+ include module_class
9
10
  end
10
11
  end
11
12
  end
@@ -3,6 +3,7 @@ require_dependency 'simple_pages/application_controller'
3
3
  module SimplePages
4
4
  class PagesController < ApplicationController
5
5
  before_filter :authenticate_session!, except: [:show]
6
+
6
7
  load_resource class: 'SimplePages::Page', only: [:index]
7
8
  before_filter :new_page, only: [:new, :create]
8
9
  load_resource class: 'SimplePages::Page', find_by: :url, only: [:show, :edit, :update, :destroy]
@@ -10,7 +11,7 @@ module SimplePages
10
11
  authorize_resource class: 'SimplePages::Page', except: [:show]
11
12
 
12
13
  def index
13
- @pages = @pages.paginate page: params[:page]
14
+ @pages = @pages.paginate pagination_options
14
15
  respond_with @pages
15
16
  end
16
17
 
@@ -68,5 +69,9 @@ module SimplePages
68
69
  [author.name, author.simple_page_owner_option]
69
70
  end
70
71
  end
72
+
73
+ def pagination_options
74
+ { page: params[:page], per_page: SimplePages.pages_per_page }
75
+ end
71
76
  end
72
77
  end
@@ -1,7 +1,4 @@
1
1
  module SimplePages
2
2
  module ApplicationHelper
3
- SimplePages.helper_modules.each do |module_name|
4
- include module_name
5
- end
6
3
  end
7
4
  end
@@ -8,7 +8,7 @@ module SimplePages
8
8
  :'data-updated' => (updated_at != published_at ? 'true' : nil ),
9
9
  class: 'published_at'
10
10
  }
11
- content_tag(:time, l(published_at, format: :long), options)
11
+ content_tag :time, ::I18n.l(published_at, format: :long), options
12
12
  end
13
13
 
14
14
  def author_vcard(author)
@@ -2,25 +2,20 @@ module SimplePages
2
2
  class Page < ActiveRecord::Base
3
3
  self.table_name = SimplePages.page_table_name
4
4
 
5
- attr_reader :owner
6
-
7
- attr_accessible :title, :excerpt, :content, :published_at, :owner, :layout_at
5
+ attr_accessible :title, :excerpt, :content, :published_at, :layout_at
8
6
 
9
7
  validates :url, presence: true
10
8
  validates :title, presence: true
11
9
 
12
- belongs_to :author, polymorphic: true
13
-
14
- has_many :attachments, as: :resource
15
-
16
10
  acts_as_url :title
17
11
 
18
12
  scope :published, lambda { where('published_at <= ?', Time.zone.now) }
13
+ scope :layout_at, lambda { |location| where(layout_at: location) }
19
14
 
20
15
  class << self
21
16
  def find_or_create_by_url(attrs)
22
- url = attrs.delete(:url)
23
- page = find_by_url(url)
17
+ url = attrs.delete :url
18
+ page = where(url: url).first
24
19
  if page.nil?
25
20
  page = create(attrs)
26
21
  page.url = url
@@ -34,14 +29,8 @@ module SimplePages
34
29
  url
35
30
  end
36
31
 
37
- def owner=(attrs)
38
- owner_attrs = attrs.split(',')
39
- self.author_type = owner_attrs.first
40
- self.author_id = owner_attrs.last
41
- end
42
-
43
- SimplePages.page_modules.each do |module_name|
44
- include module_name
32
+ SimplePages.page_modules.each do |module_class|
33
+ include module_class
45
34
  end
46
35
  end
47
36
  end
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Copy a SimplePages initializer and libraries to your Rails App
3
+
4
+ Example:
5
+ rails generate simple_pages:install
6
+
7
+ This will create/modify:
8
+ lib/devise_ext.rb
9
+ lib/cancan_ext.rb
10
+ config/initializers/simple_pages.rb
11
+ app/models/user.rb
@@ -0,0 +1,40 @@
1
+ module SimplePages
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc 'Copies SimplePages configuration file and libraries.'
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :user_model, default: 'user', desc: 'User model used in application.'
7
+
8
+ def copy_libraries
9
+ template 'devise_ext.rb', 'lib/devise_ext.rb'
10
+ template 'cancan_ext.rb', 'lib/cancan_ext.rb'
11
+ end
12
+
13
+ def copy_config_file
14
+ template 'simple_pages.rb', 'config/initializers/simple_pages.rb'
15
+ end
16
+
17
+ def append_user_mixin
18
+ user_model = "app/models/#{options[:user_model].downcase}.rb"
19
+ unless File.exist? user_model
20
+ raise 'You need to specify an user model. Try --user-model option'
21
+ end
22
+ insert_into_file user_model, before: /^end\n/ do
23
+ <<-CODE
24
+ def name
25
+ email
26
+ end
27
+
28
+ include SimplePages::Models::PageAuthor
29
+ CODE
30
+ end
31
+ end
32
+
33
+ def mount_routes
34
+ insert_into_file 'config/routes.rb', after: "routes.draw do\n" do
35
+ " mount SimplePages::Engine, at: '/'\n"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/concern'
2
+
3
+ module CanCanExt
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ rescue_from ::CanCan::AccessDenied do |exception|
7
+ redirect_to secure_root_url, alert: exception.message
8
+ end
9
+
10
+ helper_method :secure_root_url
11
+ end
12
+
13
+ module ClassMethods
14
+ end
15
+
16
+ protected
17
+
18
+ def current_ability
19
+ @current_ability ||= Ability.new session_user
20
+ end
21
+
22
+ def secure_root_url
23
+ main_app.root_url
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/concern'
2
+
3
+ module DeviseExt
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ helper_method :session_user
7
+ end
8
+
9
+ module ClassMethods
10
+ end
11
+
12
+ protected
13
+
14
+ def authenticate_session!
15
+ authenticate_user!
16
+ end
17
+
18
+ def session_user
19
+ current_user
20
+ end
21
+
22
+ def load_authors
23
+ @authors = User.all
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ require 'devise_ext'
2
+ require 'cancan_ext'
3
+
4
+ SimplePages.configure do |config|
5
+ # mixin controller modules.
6
+ config.controller_modules += [DeviseExt, CanCanExt]
7
+
8
+ # mixin helper modules.
9
+ # config.helper_modules += []
10
+
11
+ # set table name of Page, default to simple_pages.
12
+ # config.page_table_name = 'simple_pages'
13
+
14
+ # mixin modules for Page.
15
+ # config.page_modules += []
16
+
17
+ # set per page of pagination for page controller, default to 30.
18
+ # config.pages_per_page = 30
19
+ end
@@ -1,3 +1,3 @@
1
1
  module SimplePagesRails
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/simple_pages.rb CHANGED
@@ -1,22 +1,33 @@
1
- require 'rails-theme-helper/app_helpers'
2
-
3
1
  require 'simple_pages/engine'
4
- require 'simple_pages/page_author'
5
- require 'simple_pages/page_layout_at'
2
+ require 'simple_pages/controllers/page_layout_at'
3
+ require 'simple_pages/models/page_attachment'
4
+ require 'simple_pages/models/page_author'
5
+ require 'simple_pages/models/page_locale'
6
+ require 'simple_pages/models/page_owner'
6
7
 
7
8
  module SimplePages
8
- mattr_accessor :application_controller_modules
9
- @@application_controller_modules = []
9
+ mattr_accessor :controller_modules
10
+ @@controller_modules = [
11
+ SimplePages::Controllers::PageLayoutAt
12
+ ]
10
13
 
11
14
  mattr_accessor :helper_modules
12
- @@helper_modules = [
13
- RailsTheme::LayoutHelper,
14
- RailsTheme::BootstrapHelper
15
- ]
15
+ @@helper_modules = []
16
16
 
17
17
  mattr_accessor :page_table_name
18
18
  @@page_table_name = 'simple_pages'
19
19
 
20
20
  mattr_accessor :page_modules
21
- @@page_modules = []
21
+ @@page_modules = [
22
+ SimplePages::Models::PageOwner,
23
+ SimplePages::Models::PageLocale,
24
+ SimplePages::Models::PageAttachment
25
+ ]
26
+
27
+ mattr_accessor :pages_per_page
28
+ @@pages_per_page = 30
29
+
30
+ def self.configure
31
+ yield self
32
+ end
22
33
  end
@@ -0,0 +1,34 @@
1
+ require 'active_support/concern'
2
+
3
+ module SimplePages
4
+ module Controllers
5
+ module PageLayoutAt
6
+ extend ActiveSupport::Concern
7
+ included do
8
+ cattr_accessor :page_layout_at
9
+ self.page_layout_at = %w{header footer}
10
+
11
+ helper_method :pages_layout_at
12
+ end
13
+
14
+ module ClassMethods
15
+ def has_page_layout_at=(layouts = [])
16
+ self.page_layout_at += layouts unless layouts.blank?
17
+ end
18
+ alias :has_page_layout_at :has_page_layout_at=
19
+ end
20
+
21
+ protected
22
+
23
+ def pages_layout_at(location)
24
+ SimplePages::Page.layout_at(location).published
25
+ end
26
+
27
+ def load_page_layout_at_options
28
+ @layout_at_options = page_layout_at.map do |key|
29
+ [t(key, scope: 'simple_pages.layout_at'), key]
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,17 @@
1
1
  module SimplePages
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace SimplePages
4
+
5
+ config.generators.stylesheet_engine :sass
6
+ config.generators.integration_tool :rspec
7
+ config.generators.test_framework :rspec
8
+ config.generators.fixture_replacement :factory_girl, dir: 'spec/factories'
4
9
  end
5
10
  end
11
+
12
+ require 'jquery-rails'
13
+ require 'will_paginate'
14
+ require 'rails-theme-helper'
15
+ require 'chosen-rails'
16
+ require 'ckeditor_rails'
17
+ require 'stringex'