blacksand 2.2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +27 -0
  4. data/app/assets/javascripts/blacksand/dashboard/navigations.form.js.erb +34 -0
  5. data/app/assets/javascripts/blacksand/dashboard/navigations.index.js +18 -0
  6. data/app/assets/javascripts/blacksand/dashboard/pages.form.js.erb +69 -0
  7. data/app/assets/javascripts/blacksand/dashboard/pages.index.js +17 -0
  8. data/app/assets/javascripts/blacksand/dashboard.js +14 -0
  9. data/app/assets/javascripts/blacksand/ie.js +2 -0
  10. data/app/assets/javascripts/bootstrap-datepicker.zh-CN.js +20 -0
  11. data/app/assets/stylesheets/blacksand/dashboard.scss +26 -0
  12. data/app/controllers/blacksand/dashboard/base_controller.rb +35 -0
  13. data/app/controllers/blacksand/dashboard/navigations_controller.rb +88 -0
  14. data/app/controllers/blacksand/dashboard/pages_controller.rb +176 -0
  15. data/app/controllers/blacksand/dashboard/prototypes_controller.rb +12 -0
  16. data/app/controllers/blacksand/dashboard/templates_controller.rb +8 -0
  17. data/app/controllers/blacksand/dashboard/users_controller.rb +78 -0
  18. data/app/controllers/blacksand_front/pages_controller.rb +17 -0
  19. data/app/helpers/blacksand/application_helper.rb +42 -0
  20. data/app/helpers/blacksand/page_helper.rb +11 -0
  21. data/app/helpers/blacksand_front/pages_helper.rb +20 -0
  22. data/app/models/blacksand/field.rb +35 -0
  23. data/app/models/blacksand/navigation.rb +24 -0
  24. data/app/models/blacksand/page.rb +194 -0
  25. data/app/models/blacksand/picture.rb +7 -0
  26. data/app/models/blacksand/property/as_array.rb +5 -0
  27. data/app/models/blacksand/property/file.rb +5 -0
  28. data/app/models/blacksand/property/gallery.rb +7 -0
  29. data/app/models/blacksand/property/slide.rb +5 -0
  30. data/app/models/blacksand/property.rb +76 -0
  31. data/app/models/blacksand/prototype.rb +11 -0
  32. data/app/models/blacksand/template.rb +9 -0
  33. data/app/models/kindeditor/asset.rb +14 -0
  34. data/app/models/kindeditor/file.rb +3 -0
  35. data/app/models/kindeditor/flash.rb +3 -0
  36. data/app/models/kindeditor/image.rb +3 -0
  37. data/app/models/kindeditor/media.rb +3 -0
  38. data/app/uploaders/blacksand/base_uploader.rb +16 -0
  39. data/app/uploaders/blacksand/file_uploader.rb +4 -0
  40. data/app/uploaders/blacksand/image_uploader.rb +78 -0
  41. data/app/uploaders/blacksand/slide_image_uploader.rb +66 -0
  42. data/app/views/blacksand/dashboard/navigations/_form.html.erb +23 -0
  43. data/app/views/blacksand/dashboard/navigations/edit.html.erb +3 -0
  44. data/app/views/blacksand/dashboard/navigations/index.html.erb +40 -0
  45. data/app/views/blacksand/dashboard/navigations/index.json.jbuilder +4 -0
  46. data/app/views/blacksand/dashboard/navigations/new.html.erb +3 -0
  47. data/app/views/blacksand/dashboard/navigations/reorder.js.erb +1 -0
  48. data/app/views/blacksand/dashboard/navigations/show.html.erb +4 -0
  49. data/app/views/blacksand/dashboard/navigations/show.json.jbuilder +1 -0
  50. data/app/views/blacksand/dashboard/pages/_fields.html.erb +89 -0
  51. data/app/views/blacksand/dashboard/pages/_form.html.erb +26 -0
  52. data/app/views/blacksand/dashboard/pages/_manage_list.html.erb +123 -0
  53. data/app/views/blacksand/dashboard/pages/_picture_fields.html.erb +18 -0
  54. data/app/views/blacksand/dashboard/pages/children_partial.js.erb +14 -0
  55. data/app/views/blacksand/dashboard/pages/edit.html.erb +20 -0
  56. data/app/views/blacksand/dashboard/pages/index.html.erb +27 -0
  57. data/app/views/blacksand/dashboard/pages/new.html.erb +20 -0
  58. data/app/views/blacksand/dashboard/pages/onchange_render.js.erb +14 -0
  59. data/app/views/blacksand/dashboard/pages/search.json.jbuilder +7 -0
  60. data/app/views/blacksand/dashboard/pages/show.html.erb +34 -0
  61. data/app/views/blacksand/dashboard/prototypes/index.html.erb +15 -0
  62. data/app/views/blacksand/dashboard/prototypes/show.html.erb +31 -0
  63. data/app/views/blacksand/dashboard/templates/index.html.erb +17 -0
  64. data/app/views/blacksand/dashboard/users/_form.html.erb +40 -0
  65. data/app/views/blacksand/dashboard/users/edit.html.erb +47 -0
  66. data/app/views/blacksand/dashboard/users/index.html.erb +37 -0
  67. data/app/views/blacksand/dashboard/users/index.json.jbuilder +4 -0
  68. data/app/views/blacksand/dashboard/users/new.html.erb +4 -0
  69. data/app/views/blacksand/dashboard/users/show.html.erb +2 -0
  70. data/app/views/blacksand/dashboard/users/show.json.jbuilder +1 -0
  71. data/app/views/layouts/blacksand/_navbar.html.erb +42 -0
  72. data/app/views/layouts/blacksand/dashboard.html.erb +33 -0
  73. data/config/locales/kaminari.zh-CN.yml +17 -0
  74. data/config/locales/nestable.zh-CN.yml +14 -0
  75. data/config/locales/zh-CN.yml +69 -0
  76. data/config/routes.rb +31 -0
  77. data/db/migrate/20151112055035_create_templates.rb +10 -0
  78. data/db/migrate/20151112055425_create_prototypes.rb +9 -0
  79. data/db/migrate/20151112055438_create_fields.rb +14 -0
  80. data/db/migrate/20151112055821_create_pages.rb +15 -0
  81. data/db/migrate/20151112060015_create_properties.rb +15 -0
  82. data/db/migrate/20151112060605_create_navigations.rb +13 -0
  83. data/db/migrate/20151209022305_create_kindeditor_assets.rb +17 -0
  84. data/db/migrate/20160513080702_create_pictures.rb +12 -0
  85. data/db/migrate/20170104014706_add_values_to_properties.rb +5 -0
  86. data/db/migrate/20170310092041_add_owner_type_to_kindeditor_asset.rb +5 -0
  87. data/db/migrate/20170322021913_add_options_to_template_and_prototype.rb +6 -0
  88. data/lib/blacksand/caching_pages.rb +16 -0
  89. data/lib/blacksand/cancancan.rb +19 -0
  90. data/lib/blacksand/controller_helper.rb +21 -0
  91. data/lib/blacksand/engine.rb +69 -0
  92. data/lib/blacksand/expire_pages.rb +21 -0
  93. data/lib/blacksand/my_json_type.rb +61 -0
  94. data/lib/blacksand/routing.rb +11 -0
  95. data/lib/blacksand/version.rb +3 -0
  96. data/lib/blacksand.rb +53 -0
  97. data/lib/generators/blacksand/install_generator.rb +30 -0
  98. data/lib/generators/blacksand/new_site_generator.rb +28 -0
  99. data/lib/tasks/blacksand_tasks.rake +72 -0
  100. data/lib/tasks/carrierwave_storage_migrate_to_qiniu.rake +25 -0
  101. metadata +541 -0
@@ -0,0 +1,37 @@
1
+ <h2>用户列表</h2>
2
+
3
+ <%= link_to '添加用户', new_dashboard_user_path, class: 'btn btn-default' %>
4
+
5
+ <table class="table">
6
+ <thead>
7
+ <tr>
8
+ <th>顺序</th>
9
+ <th>邮箱</th>
10
+ <th>验证</th>
11
+ <th>角色</th>
12
+ <th></th>
13
+ </tr>
14
+ </thead>
15
+
16
+ <tbody>
17
+ <% @users.each_with_index do |user, i| %>
18
+ <tr>
19
+ <td><%= i + 1 %></td>
20
+ <td><%= user.email %></td>
21
+ <td><%= user.confirmed_at.present? ? '已验证' : '未验证' %></td>
22
+ <td><%= user.role.text %></td>
23
+ <td>
24
+ <% if can? :edit, user %>
25
+ <%= link_to '编辑', edit_dashboard_user_path(user), class: 'btn btn-default btn-sm' if can? :edit, user %>
26
+ <% else %>
27
+ 自己
28
+ <% end %>
29
+ <% if user.confirmed_at.blank? %>
30
+ <%= link_to '删除', dashboard_user_path(user), method: :delete, data: { confirm: '确定删除?' } %>
31
+ <% end %>
32
+ </td>
33
+ </tr>
34
+ <% end %>
35
+ </tbody>
36
+ </table>
37
+
@@ -0,0 +1,4 @@
1
+ json.array!(@users) do |user|
2
+ json.extract! user, :id
3
+ json.url user_url(user, format: :json)
4
+ end
@@ -0,0 +1,4 @@
1
+ <h2>添加用户</h2>
2
+
3
+ <%= render 'form' %>
4
+
@@ -0,0 +1,2 @@
1
+ <%= link_to t('edit'), edit_user_path(@user) %> |
2
+ <%= link_to t('back'), users_path %>
@@ -0,0 +1 @@
1
+ json.extract! @user, :id, :created_at, :updated_at
@@ -0,0 +1,42 @@
1
+ <nav id="navbar" class="navbar navbar-inverse">
2
+ <div class="container">
3
+ <!-- Brand and toggle get grouped for better mobile display -->
4
+ <div class="navbar-header">
5
+ <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
6
+ <span class="sr-only">Toggle navigation</span>
7
+ <span class="icon-bar"></span>
8
+ <span class="icon-bar"></span>
9
+ <span class="icon-bar"></span>
10
+ </button>
11
+ <a class="navbar-brand" href="<%= Blacksand.root_path %>">后台管理 - <%= Blacksand.site_name %></a>
12
+ </div>
13
+
14
+ <!-- Collect the nav links, forms, and other content for toggling -->
15
+ <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
16
+ <ul class="nav navbar-nav">
17
+ <li><a href="<%= pages_path %>">页面</a></li>
18
+ <li><a href="<%= navigations_path %>">导航</a></li>
19
+ <li><a href="<%= templates_path %>">模板</a></li>
20
+ <li><a href="<%= prototypes_path %>">原型</a></li>
21
+ <% if false && can?(:create, User) %>
22
+ <li><a href="<%= users_path %>">用户</a></li>
23
+ <% end %>
24
+ <li><a href="<%= main_app.root_path %>">回首页<span class="sr-only">(current)</span></a></li>
25
+ </ul>
26
+
27
+ <ul class="nav navbar-nav navbar-right">
28
+ <% if false && user_signed_in? %>
29
+ <li>
30
+ <span class="navbar-text text-muted"><%= current_user.email%>已登录</span>
31
+ </li>
32
+ <li>
33
+ <%= link_to destroy_user_session_path, method: :delete do %>
34
+ <i class="glyphicon glyphicon-log-out"></i>
35
+ 退出
36
+ <% end %>
37
+ </li>
38
+ <% end %>
39
+ </ul>
40
+ </div><!-- /.navbar-collapse -->
41
+ </div><!-- /.container-fluid -->
42
+ </nav>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <%= display_meta_tags site: Blacksand.site_name, reverse: true %>
8
+ <%= csrf_meta_tags %>
9
+ <%= content_for :head if content_for? :head %>
10
+
11
+ <%= stylesheet_link_tag 'blacksand/dashboard', media: 'all' %>
12
+
13
+ <!--[if lt IE 9]>
14
+ <%= javascript_include_tag 'blacksand/ie' %>
15
+ <![endif]-->
16
+
17
+ <%= Gon::Base.render_data %>
18
+ </head>
19
+ <body id="<%= "#{controller_name}-#{action_name}" %>"
20
+ data-controller="<%= controller_name %>"
21
+ data-action="<%= action_name %>">
22
+ <%= javascript_include_tag 'blacksand/dashboard' %>
23
+ <%= render 'layouts/blacksand/navbar' %>
24
+
25
+ <div class="container">
26
+
27
+ <%= yield %>
28
+
29
+ </div>
30
+
31
+ <%= content_for :javascript if content_for? :javascript %>
32
+ </body>
33
+ </html>
@@ -0,0 +1,17 @@
1
+ zh-CN:
2
+ views:
3
+ pagination:
4
+ first: "&laquo; 第一页"
5
+ last: "最后一页 &raquo;"
6
+ previous: "&lsaquo; 上一页"
7
+ next: "下一页 &rsaquo;"
8
+ truncate: "&hellip;"
9
+ helpers:
10
+ page_entries_info:
11
+ one_page:
12
+ display_entries:
13
+ zero: "No %{entry_name} found"
14
+ one: "Displaying <b>1</b> %{entry_name}"
15
+ other: "Displaying <b>all %{count}</b> %{entry_name}"
16
+ more_pages:
17
+ display_entries: "Displaying %{entry_name} <b>%{first}&nbsp;-&nbsp;%{last}</b> of <b>%{total}</b> in total"
@@ -0,0 +1,14 @@
1
+ zh-CN:
2
+ admin:
3
+ actions:
4
+ nestable:
5
+ title: "%{model_label}排序"
6
+ menu: "排序"
7
+ breadcrumb: "排序"
8
+ link: "排序"
9
+ bulk_link: "排序选取的%{model_label_plural}"
10
+ done: "完成"
11
+ success: "排序成功"
12
+ error: "错误"
13
+ update: "更新"
14
+ live_update: "实时更新"
@@ -0,0 +1,69 @@
1
+ zh-CN:
2
+ activerecord:
3
+ models:
4
+ user: 用户
5
+ blacksand/template: 模板
6
+ blacksand/prototype: 原型
7
+ blacksand/field: 字段
8
+ blacksand/page: 页面
9
+ blacksand/property: 属性
10
+ blacksand/navigation: 导航
11
+ attributes:
12
+ user:
13
+ email: "邮箱"
14
+ current_password: "当前密码"
15
+ username: "用户名"
16
+ password: "密码"
17
+ password_confirmation: "密码确认"
18
+ remember_me: "记住我"
19
+ role: 角色
20
+ page: 负责板块
21
+ blacksand/template:
22
+ name: 名称
23
+ path: 路径
24
+ blacksand/prototype:
25
+ name: 名称
26
+ blacksand/field:
27
+ description: 描述
28
+ name: 字段名(英文)
29
+ field_type: 类型
30
+ prototype: 原型
31
+ blacksand/page:
32
+ title: 标题
33
+ en_name: 英文名
34
+ content: 内容
35
+ parent: 父页面
36
+ template: 模板
37
+ prototype: 原型
38
+ position: 位置
39
+ parent_id: 父页面
40
+ template_id: 模板
41
+ prototype_id: 原型
42
+ blacksand/navigation:
43
+ name: 名称
44
+ url: 地址
45
+ page: 页面
46
+ page_id: 页面
47
+ position: 位置
48
+ blacksand/property:
49
+ value: 值
50
+ page: 页面
51
+ field: 字段
52
+ blacksand/picture:
53
+ name: 名称
54
+ file: 图片
55
+ enumerize:
56
+ field:
57
+ field_type:
58
+ string: 字符串
59
+ number: 数字
60
+ date: 日期
61
+ textarea: 文本域
62
+ rich_text: 富文本
63
+ image: 图片
64
+ gallery: 相册
65
+ user:
66
+ role:
67
+ admin: 高级管理员
68
+ manager: 管理员
69
+ editor: 编辑
data/config/routes.rb ADDED
@@ -0,0 +1,31 @@
1
+ Blacksand::Engine.routes.draw do
2
+ scope module: :dashboard do
3
+ get '/' => 'pages#default'
4
+
5
+ # TODO
6
+ # resources :users
7
+
8
+ resources :pages, except: [:show] do
9
+ collection do
10
+ get 'onchange_new'
11
+ post 'sort'
12
+
13
+ get 'children_partial'
14
+ get 'search'
15
+ end
16
+
17
+ member do
18
+ get 'onchange_edit'
19
+ get 'get_prototype_id'
20
+ get 'render_manage'
21
+ end
22
+ end
23
+
24
+ resources :navigations do
25
+ post :reorder, on: :collection
26
+ end
27
+
28
+ resources :templates, only: [:index]
29
+ resources :prototypes, only: [:index, :show]
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ class CreateTemplates < ActiveRecord::Migration
2
+ def change
3
+ create_table :templates do |t|
4
+ t.string :name
5
+ t.string :path
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePrototypes < ActiveRecord::Migration
2
+ def change
3
+ create_table :prototypes do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ class CreateFields < ActiveRecord::Migration
2
+ def change
3
+ create_table :fields do |t|
4
+ t.string :name
5
+ t.string :description
6
+ t.string :field_type
7
+ t.references :prototype, index: true, foreign_key: true
8
+ t.json :options
9
+ t.boolean :required, :default => false
10
+
11
+ t.timestamps null: false
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class CreatePages < ActiveRecord::Migration
2
+ def change
3
+ create_table :pages do |t|
4
+ t.string :title
5
+ t.string :en_name
6
+ t.text :content
7
+ t.integer :parent_id
8
+ t.references :template, index: true, foreign_key: true
9
+ t.references :prototype, index: true, foreign_key: true
10
+ t.integer :position, default: 0
11
+
12
+ t.timestamps null: false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class CreateProperties < ActiveRecord::Migration
2
+ def change
3
+ create_table :properties do |t|
4
+ t.text :value
5
+ t.references :page, index: true, foreign_key: true
6
+ t.references :field, index: true, foreign_key: true
7
+ t.string :type
8
+ t.json :gallery
9
+ t.string :image
10
+ t.string :file
11
+
12
+ t.timestamps null: false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class CreateNavigations < ActiveRecord::Migration
2
+ def change
3
+ create_table :navigations do |t|
4
+ t.string :name
5
+ t.string :url
6
+ t.integer :position, default: 0
7
+ t.references :page, index: true, foreign_key: true
8
+ t.json :options
9
+
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ class CreateKindeditorAssets < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :kindeditor_assets do |t|
4
+ t.string :asset
5
+ t.integer :file_size
6
+ t.string :file_type
7
+ t.integer :owner_id
8
+ t.string :asset_type # list by kindeditor: image, file, media, flash
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :kindeditor_assets
15
+ end
16
+ end
17
+
@@ -0,0 +1,12 @@
1
+ class CreatePictures < ActiveRecord::Migration
2
+ def change
3
+ create_table :pictures do |t|
4
+ t.string :name
5
+ t.string :file
6
+ t.integer :imageable_id
7
+ t.string :imageable_type
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddValuesToProperties < ActiveRecord::Migration
2
+ def change
3
+ add_column :properties, :values, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddOwnerTypeToKindeditorAsset < ActiveRecord::Migration
2
+ def change
3
+ add_column :kindeditor_assets, :owner_type, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddOptionsToTemplateAndPrototype < ActiveRecord::Migration
2
+ def change
3
+ add_column :templates, :options, :json
4
+ add_column :prototypes, :options, :json
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ module Blacksand
2
+ module CachingPages
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ caches_page :show
7
+ end
8
+
9
+ # 覆盖 actionpack-page_caching 的方法,如果页面带参数将不会生成缓存页。例如带分页的页面。
10
+ def caching_allowed?
11
+ return false if request.query_string.present?
12
+
13
+ super
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module Blacksand
2
+
3
+ class Cancancan
4
+ def initialize(controller)
5
+ @controller = controller
6
+ @controller.extend ControllerExtension
7
+ end
8
+
9
+ def authorized?(action, object)
10
+ @controller.current_ability.can?(action, object)
11
+ end
12
+
13
+ module ControllerExtension
14
+ def current_ability
15
+ @current_ability ||= ::Ability.new(_current_user)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Blacksand
2
+ module ControllerHelper
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+
7
+ # 应用 theme, 加载导航, 引用 helper method 到 view
8
+ def blacksand
9
+ theme Blacksand.site_id
10
+ loan_navigations
11
+ helper BlacksandFront::PagesHelper
12
+ end
13
+
14
+ def loan_navigations
15
+ before_action do
16
+ @navigations = Blacksand::Navigation.includes(page: :positioned_children).order(:position)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ require 'rails'
2
+ require 'carrierwave'
3
+ require 'carrierwave-qiniu'
4
+ require 'rails_kindeditor'
5
+ require 'mini_magick'
6
+ require 'kaminari'
7
+ require 'bootstrap-kaminari-views'
8
+ require 'gon'
9
+ require 'meta-tags'
10
+ require 'bootstrap-sass'
11
+ require 'bootstrap_form'
12
+ require 'cocoon'
13
+ require 'font-awesome-rails'
14
+ require 'enumerize'
15
+ require 'ransack'
16
+ require 'themes_on_rails'
17
+ require 'actionpack/page_caching'
18
+
19
+ require 'rails-assets-util.css'
20
+ require 'rails-assets-html5shiv'
21
+ require 'rails-assets-respond'
22
+ require 'rails-assets-bootstrap-datepicker'
23
+ require 'rails-assets-headroom.js'
24
+ require 'rails-assets-dragula'
25
+ require 'rails-assets-bootstrap-treeview'
26
+ require 'rails-assets-multiselect'
27
+ require 'rails-assets-select2'
28
+
29
+ require 'blacksand/routing'
30
+ require 'blacksand/controller_helper'
31
+ require 'blacksand/caching_pages'
32
+ require 'blacksand/expire_pages'
33
+
34
+ module Blacksand
35
+
36
+ class Engine < ::Rails::Engine
37
+ isolate_namespace Blacksand
38
+
39
+ # USING: rake blacksand_engine:install:migrations
40
+
41
+ initializer "blacksand.precompile", group: :all do |app|
42
+ app.config.assets.precompile += %w(
43
+ blacksand/dashboard.js
44
+ blacksand/dashboard.css
45
+ blacksand/ie.js
46
+ )
47
+ end
48
+
49
+ initializer "blacksand.override_upload_storage", after: "rails_kindeditor.image_process" do
50
+ # Storage be same with Our uploaders
51
+ Kindeditor::AssetUploader.class_eval do
52
+ storage Blacksand.carrierwave_storage
53
+ end
54
+ end
55
+
56
+ initializer "blacksand.page_caching", after: 'action_pack.page_caching' do |app|
57
+ if Blacksand.page_caching
58
+ BlacksandFront::PagesController.send(:include, CachingPages)
59
+ Blacksand::Dashboard::PagesController.send(:include, ExpirePages)
60
+ Blacksand::Dashboard::NavigationsController.send(:include, ExpirePages)
61
+ end
62
+ end
63
+
64
+ ActiveSupport.on_load :action_controller do
65
+ include ControllerHelper
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,21 @@
1
+ module Blacksand
2
+ module ExpirePages
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ after_action :expire_cache_pages, only: [:create, :update, :destroy]
7
+ end
8
+
9
+
10
+ def expire_cache_pages
11
+ if defined? Rails.application.routes.url_helpers.root_path
12
+ expire_page Rails.application.routes.url_helpers.root_path
13
+ end
14
+
15
+ # TODO: 有点暴力, 可以扫描缓存文件夹,挨个删除
16
+ Blacksand::Page.find_each do |p|
17
+ expire_page Rails.application.routes.url_helpers.page_path(p)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ require 'ostruct'
2
+ require 'active_record/connection_adapters/postgresql/oid/json'
3
+
4
+ module Blacksand
5
+ # 为了能使 form 获取对象的状态,因为获取状态是使用 obj.send(name). 而默认 hash 是不能工作的。
6
+ class MyJsonType < ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json
7
+
8
+ # override active_record 4
9
+ def type_cast_from_database(value)
10
+ super_value = super
11
+
12
+ if value.is_a?(::String)
13
+ MyOpenStruct.new super_value
14
+ else
15
+ super_value
16
+ end
17
+ end
18
+
19
+ # override active_record 4
20
+ def type_cast_for_database(value)
21
+ if value.is_a? MyOpenStruct
22
+ ::ActiveSupport::JSON.encode(value.to_h)
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+
29
+ # override active_record 5
30
+ def deserialize(value)
31
+ super_value = super
32
+
33
+ if value.is_a?(::String)
34
+ MyOpenStruct.new super_value
35
+ else
36
+ super_value
37
+ end
38
+ end
39
+
40
+ # override active_record 5
41
+ def serialize(value)
42
+ if value.is_a? MyOpenStruct
43
+ ::ActiveSupport::JSON.encode(value.to_h)
44
+ else
45
+ super
46
+ end
47
+ end
48
+ end
49
+
50
+ class MyOpenStruct < OpenStruct
51
+ # hack for bootstrap_form FormBuilder#required_attribute?
52
+ def self.validators_on(*args)
53
+ []
54
+ end
55
+ end
56
+ end
57
+
58
+ if ActiveRecord::VERSION::MAJOR >= 5
59
+ puts "ActiveRecord Register json_type => Blacksand::MyJsonType, at #{__FILE__}:#{__LINE__}"
60
+ ActiveRecord::Type.register(:json_type, Blacksand::MyJsonType, adapter: :postgresql)
61
+ end
@@ -0,0 +1,11 @@
1
+ module Blacksand
2
+ module Routing
3
+ def blacksand(path = :p)
4
+ scope module: 'blacksand_front' do
5
+ resources :pages, only: :show, path: path
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ ActionDispatch::Routing::Mapper.send :include, Blacksand::Routing
@@ -0,0 +1,3 @@
1
+ module Blacksand
2
+ VERSION = "2.2.2.1"
3
+ end