simple-pages-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. data/.gitignore +8 -0
  2. data/Gemfile +17 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +27 -0
  6. data/app/assets/images/simple_pages/.gitkeep +0 -0
  7. data/app/assets/javascripts/simple_pages/application.js +20 -0
  8. data/app/assets/javascripts/simple_pages/ckeditor/config.js.coffee +2 -0
  9. data/app/assets/javascripts/simple_pages/pages.js.coffee +0 -0
  10. data/app/assets/stylesheets/simple_pages/application.css +17 -0
  11. data/app/assets/stylesheets/simple_pages/ckeditor/content.css.sass +0 -0
  12. data/app/assets/stylesheets/simple_pages/pages.css.sass +0 -0
  13. data/app/controllers/simple_pages/application_controller.rb +11 -0
  14. data/app/controllers/simple_pages/pages_controller.rb +72 -0
  15. data/app/helpers/simple_pages/application_helper.rb +7 -0
  16. data/app/helpers/simple_pages/pages_helper.rb +28 -0
  17. data/app/models/simple_pages/page.rb +47 -0
  18. data/app/views/layouts/simple_pages/application.html.erb +51 -0
  19. data/app/views/simple_pages/pages/_form.html.erb +10 -0
  20. data/app/views/simple_pages/pages/_table.html.erb +32 -0
  21. data/app/views/simple_pages/pages/edit.html.erb +26 -0
  22. data/app/views/simple_pages/pages/index.html.erb +17 -0
  23. data/app/views/simple_pages/pages/new.html.erb +23 -0
  24. data/app/views/simple_pages/pages/show.html.erb +26 -0
  25. data/config/locales/pages.en.yml +40 -0
  26. data/config/locales/pages.zh-TW.yml +40 -0
  27. data/config/locales/simple_pages.en.yml +13 -0
  28. data/config/locales/simple_pages.zh-TW.yml +13 -0
  29. data/config/routes.rb +3 -0
  30. data/db/migrate/20121206042138_create_simple_pages.rb +18 -0
  31. data/lib/simple-pages-rails.rb +1 -0
  32. data/lib/simple-pages-rails/version.rb +3 -0
  33. data/lib/simple_pages.rb +22 -0
  34. data/lib/simple_pages/engine.rb +5 -0
  35. data/lib/simple_pages/page_author.rb +17 -0
  36. data/lib/simple_pages/page_layout_at.rb +32 -0
  37. data/lib/tasks/simple_pages_tasks.rake +4 -0
  38. data/script/rails +8 -0
  39. data/simple-pages-rails.gemspec +25 -0
  40. data/spec/dummy/README.rdoc +261 -0
  41. data/spec/dummy/Rakefile +7 -0
  42. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  43. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  44. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  46. data/spec/dummy/app/mailers/.gitkeep +0 -0
  47. data/spec/dummy/app/models/.gitkeep +0 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/spec/dummy/config.ru +4 -0
  50. data/spec/dummy/config/application.rb +65 -0
  51. data/spec/dummy/config/boot.rb +10 -0
  52. data/spec/dummy/config/database.yml +42 -0
  53. data/spec/dummy/config/environment.rb +5 -0
  54. data/spec/dummy/config/environments/development.rb +37 -0
  55. data/spec/dummy/config/environments/production.rb +67 -0
  56. data/spec/dummy/config/environments/test.rb +37 -0
  57. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/dummy/config/initializers/inflections.rb +15 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  60. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  61. data/spec/dummy/config/initializers/session_store.rb +8 -0
  62. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  63. data/spec/dummy/config/locales/en.yml +5 -0
  64. data/spec/dummy/config/routes.rb +4 -0
  65. data/spec/dummy/lib/assets/.gitkeep +0 -0
  66. data/spec/dummy/log/.gitkeep +0 -0
  67. data/spec/dummy/public/404.html +26 -0
  68. data/spec/dummy/public/422.html +26 -0
  69. data/spec/dummy/public/500.html +25 -0
  70. data/spec/dummy/public/favicon.ico +0 -0
  71. data/spec/dummy/script/rails +6 -0
  72. metadata +202 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ Gemfile.lock
3
+ log/*.log
4
+ pkg/
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in simple_pages.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tse-Ching Ho
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Simple::Pages::Rails
2
+
3
+ This gem provides simple pages with rails engine
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple-pages-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple-pages-rails
18
+
19
+ ## Usage
20
+
21
+
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SimplePages'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
File without changes
@@ -0,0 +1,20 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require jquery
16
+ //= require jquery_ujs
17
+ //= require twitter/bootstrap
18
+ //= require chosen-jquery
19
+ //= require ckeditor-jquery
20
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ CKEDITOR.editorConfig = (config) ->
2
+ true
@@ -0,0 +1,17 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require twitter/bootstrap
12
+ *= require twitter/bootstrap-responsive
13
+ *= require chosen
14
+ *= require rails_theme/simple_layout
15
+ *= require_self
16
+ *= require_tree .
17
+ */
@@ -0,0 +1,11 @@
1
+ module SimplePages
2
+ class ApplicationController < ActionController::Base
3
+ include SimplePages::PageLayoutAt
4
+
5
+ respond_to :html
6
+
7
+ SimplePages.application_controller_modules.each do |module_name|
8
+ include module_name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,72 @@
1
+ require_dependency 'simple_pages/application_controller'
2
+
3
+ module SimplePages
4
+ class PagesController < ApplicationController
5
+ before_filter :authenticate_session!, except: [:show]
6
+ load_resource class: 'SimplePages::Page', only: [:index]
7
+ before_filter :new_page, only: [:new, :create]
8
+ load_resource class: 'SimplePages::Page', find_by: :url, only: [:show, :edit, :update, :destroy]
9
+
10
+ authorize_resource class: 'SimplePages::Page', except: [:show]
11
+
12
+ def index
13
+ @pages = @pages.paginate page: params[:page]
14
+ respond_with @pages
15
+ end
16
+
17
+ def show
18
+ respond_with @page
19
+ end
20
+
21
+ def new
22
+ load_page_options
23
+ @page.author = session_user
24
+ respond_with @page
25
+ end
26
+
27
+ def edit
28
+ load_page_options
29
+ end
30
+
31
+ def create
32
+ @page.save
33
+ if @page.invalid?
34
+ load_page_options
35
+ end
36
+ respond_with @page
37
+ end
38
+
39
+ def update
40
+ @page.update_attributes params[:page]
41
+ if @page.invalid?
42
+ load_page_options
43
+ end
44
+ respond_with @page
45
+ end
46
+
47
+ def destroy
48
+ @page.destroy
49
+ respond_with @page
50
+ end
51
+
52
+ protected
53
+
54
+ def new_page
55
+ @page = SimplePages::Page.new params[:page]
56
+ end
57
+
58
+ def load_page_options
59
+ load_author_options
60
+ load_page_layout_at_options
61
+ end
62
+
63
+ private
64
+
65
+ def load_author_options
66
+ load_authors
67
+ @author_options = @authors.map do |author|
68
+ [author.name, author.simple_page_owner_option]
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ module SimplePages
2
+ module ApplicationHelper
3
+ SimplePages.helper_modules.each do |module_name|
4
+ include module_name
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module SimplePages
2
+ module PagesHelper
3
+ def publish_time(published_at, updated_at)
4
+ return unless published_at
5
+ options = {
6
+ datetime: published_at,
7
+ pubdate: true,
8
+ :'data-updated' => (updated_at != published_at ? 'true' : nil ),
9
+ class: 'published_at'
10
+ }
11
+ content_tag(:time, l(published_at, format: :long), options)
12
+ end
13
+
14
+ def author_vcard(author)
15
+ content_tag :span, class: 'author vcard' do
16
+ t('helpers.posted_by', name: content_tag(:span, author)).html_safe
17
+ end
18
+ end
19
+
20
+ def selected_page_author(object)
21
+ object.author.try :simple_page_owner_option
22
+ end
23
+
24
+ def local_published_at(object)
25
+ object.published_at? ? object.published_at.localtime : nil
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ module SimplePages
2
+ class Page < ActiveRecord::Base
3
+ self.table_name = SimplePages.page_table_name
4
+
5
+ attr_reader :owner
6
+
7
+ attr_accessible :title, :excerpt, :content, :published_at, :owner, :layout_at
8
+
9
+ validates :url, presence: true
10
+ validates :title, presence: true
11
+
12
+ belongs_to :author, polymorphic: true
13
+
14
+ has_many :attachments, as: :resource
15
+
16
+ acts_as_url :title
17
+
18
+ scope :published, lambda { where('published_at <= ?', Time.zone.now) }
19
+
20
+ class << self
21
+ def find_or_create_by_url(attrs)
22
+ url = attrs.delete(:url)
23
+ page = find_by_url(url)
24
+ if page.nil?
25
+ page = create(attrs)
26
+ page.url = url
27
+ page.save
28
+ end
29
+ page
30
+ end
31
+ end
32
+
33
+ def to_param
34
+ url
35
+ end
36
+
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
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,51 @@
1
+ <!DOCTYPE html>
2
+ <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
3
+ <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
4
+ <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
5
+ <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
6
+ <head>
7
+ <meta charset="utf-8">
8
+
9
+ <title><%= t('site.title') %></title>
10
+ <meta name="viewport" content="width=device-width,initial-scale=1">
11
+ <meta name="description" content="">
12
+ <meta name="keywords" content="">
13
+ <meta name="author" content="<%= t('site.author') %>">
14
+
15
+ <link rel="shortcut icon" href="/favicon.ico">
16
+
17
+ <%= stylesheet_link_tag 'simple_pages/application', media: 'all' %>
18
+ <%= csrf_meta_tags %>
19
+ </head>
20
+ <body>
21
+ <%= render 'application/chromeframe' %>
22
+
23
+ <header class="navbar navbar-inverse navbar-fixed-top">
24
+ <div class="navbar-inner">
25
+ <div class="container-fluid">
26
+ <%= render 'application/header' %>
27
+ </div>
28
+ </div>
29
+ </header>
30
+
31
+ <div role="main" id="main" class="container-fluid">
32
+ <aside role="flash_messages" class="row-fluid">
33
+ <%= render 'application/flash_messages' %>
34
+ </aside>
35
+ <div class="row-fluid">
36
+ <div class="span12 <%= controller_name %>">
37
+ <%= yield %>
38
+ </div>
39
+ </div>
40
+ </div>
41
+
42
+ <footer id="bigfoot" class="container-fluid">
43
+ <div class="row-fluid">
44
+ <%= render 'application/footer' %>
45
+ </div>
46
+ </footer>
47
+
48
+ <%= javascript_include_tag "simple_pages/application" %>
49
+ <%= render 'application/google_analytics' if Rails.env.production? %>
50
+ </body>
51
+ </html>
@@ -0,0 +1,10 @@
1
+ <%= f.error_notification %>
2
+
3
+ <div class="form-inputs">
4
+ <%= f.input :title, input_html: { class: 'span10' } %>
5
+ <%= f.input :excerpt, as: :text, input_html: { rows: 5, class: 'span10' } %>
6
+ <%= f.input :content, input_html: { class: 'ckeditor' } %>
7
+ <%= f.input :owner, collection: author_options, selected: selected_page_author(f.object), input_html: { class: 'chzn-select' } %>
8
+ <%= f.input :published_at, as: :string, input_html: { value: local_published_at(f.object), class: 'datetimepicker' } %>
9
+ <%= f.input :layout_at, as: :select, collection: layout_at_options %>
10
+ </div>
@@ -0,0 +1,32 @@
1
+ <table class="table table-striped table-bordered">
2
+ <thead>
3
+ <tr>
4
+ <th><%= SimplePages::Page.human_attribute_name(:title) %></th>
5
+ <th><%= SimplePages::Page.human_attribute_name(:layout_at) %></th>
6
+ <th><%= SimplePages::Page.human_attribute_name(:author) %></th>
7
+ <th><%= SimplePages::Page.human_attribute_name(:published_at) %></th>
8
+ <th><%= t('helpers.actions') %></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% pages.each do |page| %>
13
+ <tr>
14
+ <td><%= page.title %></td>
15
+ <td><%= t(page.layout_at, scope: 'simple_pages.layout_at') if page.layout_at? %></td>
16
+ <td><%= page.author.name %></td>
17
+ <td><%= publish_time(page.published_at, page.updated_at) %></td>
18
+ <%= render_btn_group :td do |btn|
19
+ if can? :show, page
20
+ btn << link_to_show(page_path(page))
21
+ end
22
+ if can? :edit, page
23
+ btn << link_to_edit(edit_page_path(page))
24
+ end
25
+ if can? :destroy, page
26
+ btn << link_to_destroy(page_path(page))
27
+ end
28
+ end %>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
@@ -0,0 +1,26 @@
1
+ <article>
2
+ <header>
3
+ <h1><%= t('.title') %></h1>
4
+ </header>
5
+
6
+ <%= render_list class: 'nav nav-tabs' do |li|
7
+ if can? :index, SimplePages::Page
8
+ li << [link_to(t('helpers.index'), pages_path), { class: 'pull-right' }]
9
+ end
10
+ if can? :show, @page
11
+ li << [link_to(t('helpers.show'), @page), { class: 'pull-right' }]
12
+ end
13
+ end %>
14
+
15
+ <div>
16
+ <%= simple_form_for @page, as: :page, html: { class: 'form-horizontal' } do |f| %>
17
+ <%= render 'form', f: f, author_options: @author_options, layout_at_options: @layout_at_options %>
18
+ <div class="form-actions">
19
+ <%= submit_button f %>
20
+ </div>
21
+ <% end %>
22
+ </div>
23
+
24
+ <footer>
25
+ </footer>
26
+ </article>