blacksand 2.2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +27 -0
- data/app/assets/javascripts/blacksand/dashboard/navigations.form.js.erb +34 -0
- data/app/assets/javascripts/blacksand/dashboard/navigations.index.js +18 -0
- data/app/assets/javascripts/blacksand/dashboard/pages.form.js.erb +69 -0
- data/app/assets/javascripts/blacksand/dashboard/pages.index.js +17 -0
- data/app/assets/javascripts/blacksand/dashboard.js +14 -0
- data/app/assets/javascripts/blacksand/ie.js +2 -0
- data/app/assets/javascripts/bootstrap-datepicker.zh-CN.js +20 -0
- data/app/assets/stylesheets/blacksand/dashboard.scss +26 -0
- data/app/controllers/blacksand/dashboard/base_controller.rb +35 -0
- data/app/controllers/blacksand/dashboard/navigations_controller.rb +88 -0
- data/app/controllers/blacksand/dashboard/pages_controller.rb +176 -0
- data/app/controllers/blacksand/dashboard/prototypes_controller.rb +12 -0
- data/app/controllers/blacksand/dashboard/templates_controller.rb +8 -0
- data/app/controllers/blacksand/dashboard/users_controller.rb +78 -0
- data/app/controllers/blacksand_front/pages_controller.rb +17 -0
- data/app/helpers/blacksand/application_helper.rb +42 -0
- data/app/helpers/blacksand/page_helper.rb +11 -0
- data/app/helpers/blacksand_front/pages_helper.rb +20 -0
- data/app/models/blacksand/field.rb +35 -0
- data/app/models/blacksand/navigation.rb +24 -0
- data/app/models/blacksand/page.rb +194 -0
- data/app/models/blacksand/picture.rb +7 -0
- data/app/models/blacksand/property/as_array.rb +5 -0
- data/app/models/blacksand/property/file.rb +5 -0
- data/app/models/blacksand/property/gallery.rb +7 -0
- data/app/models/blacksand/property/slide.rb +5 -0
- data/app/models/blacksand/property.rb +76 -0
- data/app/models/blacksand/prototype.rb +11 -0
- data/app/models/blacksand/template.rb +9 -0
- data/app/models/kindeditor/asset.rb +14 -0
- data/app/models/kindeditor/file.rb +3 -0
- data/app/models/kindeditor/flash.rb +3 -0
- data/app/models/kindeditor/image.rb +3 -0
- data/app/models/kindeditor/media.rb +3 -0
- data/app/uploaders/blacksand/base_uploader.rb +16 -0
- data/app/uploaders/blacksand/file_uploader.rb +4 -0
- data/app/uploaders/blacksand/image_uploader.rb +78 -0
- data/app/uploaders/blacksand/slide_image_uploader.rb +66 -0
- data/app/views/blacksand/dashboard/navigations/_form.html.erb +23 -0
- data/app/views/blacksand/dashboard/navigations/edit.html.erb +3 -0
- data/app/views/blacksand/dashboard/navigations/index.html.erb +40 -0
- data/app/views/blacksand/dashboard/navigations/index.json.jbuilder +4 -0
- data/app/views/blacksand/dashboard/navigations/new.html.erb +3 -0
- data/app/views/blacksand/dashboard/navigations/reorder.js.erb +1 -0
- data/app/views/blacksand/dashboard/navigations/show.html.erb +4 -0
- data/app/views/blacksand/dashboard/navigations/show.json.jbuilder +1 -0
- data/app/views/blacksand/dashboard/pages/_fields.html.erb +89 -0
- data/app/views/blacksand/dashboard/pages/_form.html.erb +26 -0
- data/app/views/blacksand/dashboard/pages/_manage_list.html.erb +123 -0
- data/app/views/blacksand/dashboard/pages/_picture_fields.html.erb +18 -0
- data/app/views/blacksand/dashboard/pages/children_partial.js.erb +14 -0
- data/app/views/blacksand/dashboard/pages/edit.html.erb +20 -0
- data/app/views/blacksand/dashboard/pages/index.html.erb +27 -0
- data/app/views/blacksand/dashboard/pages/new.html.erb +20 -0
- data/app/views/blacksand/dashboard/pages/onchange_render.js.erb +14 -0
- data/app/views/blacksand/dashboard/pages/search.json.jbuilder +7 -0
- data/app/views/blacksand/dashboard/pages/show.html.erb +34 -0
- data/app/views/blacksand/dashboard/prototypes/index.html.erb +15 -0
- data/app/views/blacksand/dashboard/prototypes/show.html.erb +31 -0
- data/app/views/blacksand/dashboard/templates/index.html.erb +17 -0
- data/app/views/blacksand/dashboard/users/_form.html.erb +40 -0
- data/app/views/blacksand/dashboard/users/edit.html.erb +47 -0
- data/app/views/blacksand/dashboard/users/index.html.erb +37 -0
- data/app/views/blacksand/dashboard/users/index.json.jbuilder +4 -0
- data/app/views/blacksand/dashboard/users/new.html.erb +4 -0
- data/app/views/blacksand/dashboard/users/show.html.erb +2 -0
- data/app/views/blacksand/dashboard/users/show.json.jbuilder +1 -0
- data/app/views/layouts/blacksand/_navbar.html.erb +42 -0
- data/app/views/layouts/blacksand/dashboard.html.erb +33 -0
- data/config/locales/kaminari.zh-CN.yml +17 -0
- data/config/locales/nestable.zh-CN.yml +14 -0
- data/config/locales/zh-CN.yml +69 -0
- data/config/routes.rb +31 -0
- data/db/migrate/20151112055035_create_templates.rb +10 -0
- data/db/migrate/20151112055425_create_prototypes.rb +9 -0
- data/db/migrate/20151112055438_create_fields.rb +14 -0
- data/db/migrate/20151112055821_create_pages.rb +15 -0
- data/db/migrate/20151112060015_create_properties.rb +15 -0
- data/db/migrate/20151112060605_create_navigations.rb +13 -0
- data/db/migrate/20151209022305_create_kindeditor_assets.rb +17 -0
- data/db/migrate/20160513080702_create_pictures.rb +12 -0
- data/db/migrate/20170104014706_add_values_to_properties.rb +5 -0
- data/db/migrate/20170310092041_add_owner_type_to_kindeditor_asset.rb +5 -0
- data/db/migrate/20170322021913_add_options_to_template_and_prototype.rb +6 -0
- data/lib/blacksand/caching_pages.rb +16 -0
- data/lib/blacksand/cancancan.rb +19 -0
- data/lib/blacksand/controller_helper.rb +21 -0
- data/lib/blacksand/engine.rb +69 -0
- data/lib/blacksand/expire_pages.rb +21 -0
- data/lib/blacksand/my_json_type.rb +61 -0
- data/lib/blacksand/routing.rb +11 -0
- data/lib/blacksand/version.rb +3 -0
- data/lib/blacksand.rb +53 -0
- data/lib/generators/blacksand/install_generator.rb +30 -0
- data/lib/generators/blacksand/new_site_generator.rb +28 -0
- data/lib/tasks/blacksand_tasks.rake +72 -0
- data/lib/tasks/carrierwave_storage_migrate_to_qiniu.rake +25 -0
- metadata +541 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
module Blacksand
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
def paginate objects, options = {}
|
5
|
+
options.reverse_merge!(theme: 'twitter-bootstrap-3')
|
6
|
+
|
7
|
+
super(objects, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def filed_options(f)
|
11
|
+
filed_options = {}
|
12
|
+
case f.object.field.field_type
|
13
|
+
when 'date' then
|
14
|
+
filed_options = {data: {provide: 'datepicker', 'date-format' => 'yyyy-mm-dd', 'date-language' => 'zh-CN', 'date-autoclose' => true}}
|
15
|
+
when 'gallery' then
|
16
|
+
filed_options = {multiple: true}
|
17
|
+
when 'page' then
|
18
|
+
filed_options = { class: 'test', data: {provide: 'select2'} }
|
19
|
+
end
|
20
|
+
return filed_options.merge({label: "#{f.object.field.description}", label_class: "#{'required' if f.object.field.required?}"})
|
21
|
+
end
|
22
|
+
|
23
|
+
def select_choices(f)
|
24
|
+
if f.object.value.present?
|
25
|
+
page = f.object.content
|
26
|
+
[['无', ''], ["##{page.id} #{page.title}", f.object.value]]
|
27
|
+
else
|
28
|
+
[['无', '']]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_page_options(hash)
|
33
|
+
@_page_options ||= {}
|
34
|
+
@_page_options.merge!(hash)
|
35
|
+
end
|
36
|
+
|
37
|
+
def page_options
|
38
|
+
@_page_options || {}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BlacksandFront
|
2
|
+
module PagesHelper
|
3
|
+
def page(en_name)
|
4
|
+
Blacksand::Page.where(en_name: en_name).first
|
5
|
+
end
|
6
|
+
|
7
|
+
def textarea2html(text)
|
8
|
+
text.split(' ').join('<br>').html_safe if text.present?
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_page_options(hash)
|
12
|
+
@_page_options ||= {}
|
13
|
+
@_page_options.merge!(hash)
|
14
|
+
end
|
15
|
+
|
16
|
+
def page_options
|
17
|
+
@_page_options || {}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Blacksand
|
2
|
+
class Field < ActiveRecord::Base
|
3
|
+
extend Enumerize
|
4
|
+
|
5
|
+
belongs_to :prototype
|
6
|
+
has_many :properties, dependent: :destroy
|
7
|
+
|
8
|
+
validates :name, :description, :field_type, presence: true
|
9
|
+
validates :options, presence: true, if: 'select?'
|
10
|
+
|
11
|
+
enumerize :field_type, in: %w{date number string textarea rich_text image gallery array slide file select page}
|
12
|
+
|
13
|
+
default_scope { order(:id) }
|
14
|
+
|
15
|
+
after_save :check_properties
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def select?
|
20
|
+
field_type == 'select'
|
21
|
+
end
|
22
|
+
|
23
|
+
def check_properties
|
24
|
+
# 根据 prototype 查询 page 会更高效 @gaohui 2015.11.25
|
25
|
+
self.prototype.pages.find_each do |page|
|
26
|
+
(self.prototype.fields.map(&:id) - page.properties.map(&:field_id)).each do |field_id|
|
27
|
+
field = Field.find field_id
|
28
|
+
Property.build_property(page, field)
|
29
|
+
end
|
30
|
+
page.save(validate: false)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Blacksand
|
2
|
+
class Navigation < ActiveRecord::Base
|
3
|
+
belongs_to :page
|
4
|
+
|
5
|
+
# ActiveRecord attribute api changed, see http://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
|
6
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
7
|
+
attribute :options, :json_type
|
8
|
+
else
|
9
|
+
attribute :options, MyJsonType.new
|
10
|
+
end
|
11
|
+
|
12
|
+
validates :name, presence: true
|
13
|
+
validates :url, format: {with: URI.regexp}, if: Proc.new { |a| a.url.present? }
|
14
|
+
|
15
|
+
validate :url_or_page_presence
|
16
|
+
|
17
|
+
def url_or_page_presence
|
18
|
+
if url.blank? && page_id.blank?
|
19
|
+
errors.add(:url, "链接或者页面两个必须要填一项")
|
20
|
+
errors.add(:page_id, "链接或者页面两个必须要填一项")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Blacksand
|
4
|
+
class Page < ActiveRecord::Base
|
5
|
+
belongs_to :parent, class_name: Page, foreign_key: 'parent_id'
|
6
|
+
has_many :children, class_name: Page, foreign_key: 'parent_id', :dependent => :destroy
|
7
|
+
has_one :navigation, :dependent => :destroy
|
8
|
+
|
9
|
+
belongs_to :template
|
10
|
+
belongs_to :prototype
|
11
|
+
|
12
|
+
has_many :properties, :dependent => :destroy
|
13
|
+
has_many_kindeditor_assets :attachments, :dependent => :destroy
|
14
|
+
|
15
|
+
accepts_nested_attributes_for :properties
|
16
|
+
|
17
|
+
has_many :positioned_children, -> { order(:position) }, class_name: 'Page', foreign_key: 'parent_id'
|
18
|
+
|
19
|
+
# validates :title, :template, presence: true
|
20
|
+
|
21
|
+
# 在新建页面的时候,上传的图片没有 owner_id 和 owner_type
|
22
|
+
# TODO: 还有一种情况是在新建页面的时候,图片上传上来后又被删除了。这时候图片就变成没有人认领的孤儿了。
|
23
|
+
after_commit :set_owner_for_kindeditor_assets, on: :create
|
24
|
+
|
25
|
+
# 在编辑的过程中可能从内容中删除了部分图片, 但是 Kinkeditor::Assets 还没有被删除
|
26
|
+
after_commit :clean_unsued_kindeditor_assets, on: :update
|
27
|
+
|
28
|
+
# page.props.name
|
29
|
+
# page.props[:name]
|
30
|
+
def props
|
31
|
+
if @attrs.blank?
|
32
|
+
properties = self.properties.includes(:field).map { |p| [p.field.name, p.content] }
|
33
|
+
@attrs = OpenStruct.new(Hash[properties])
|
34
|
+
end
|
35
|
+
|
36
|
+
@attrs
|
37
|
+
end
|
38
|
+
|
39
|
+
# 推荐使用 props 方法 @gaohui 2015.11.26
|
40
|
+
def values
|
41
|
+
if @values.blank?
|
42
|
+
@values = ActiveSupport::HashWithIndifferentAccess.new
|
43
|
+
self.properties.each do |p|
|
44
|
+
@values[p.field.name] = p.content
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
@values
|
49
|
+
end
|
50
|
+
|
51
|
+
def ancestors
|
52
|
+
if self.parent.present?
|
53
|
+
self.parent.ancestors + [self.parent]
|
54
|
+
else
|
55
|
+
[]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def descendents
|
60
|
+
self.positioned_children.reduce([]) do |all, child|
|
61
|
+
all << child
|
62
|
+
all.concat(child.descendents)
|
63
|
+
all
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def child(title)
|
68
|
+
self.children.where(title: title).first
|
69
|
+
end
|
70
|
+
|
71
|
+
def child_with(conditions)
|
72
|
+
self.children.find_by(conditions)
|
73
|
+
end
|
74
|
+
|
75
|
+
def content_first_image
|
76
|
+
image_assets = image_assets_of_content
|
77
|
+
|
78
|
+
return if image_assets.empty?
|
79
|
+
|
80
|
+
asset_name = image_assets.first
|
81
|
+
Kindeditor::Asset.where(asset: asset_name).first
|
82
|
+
end
|
83
|
+
|
84
|
+
def all_image_srcs_of_content
|
85
|
+
html_doc = Nokogiri::HTML(self.content)
|
86
|
+
images = html_doc.xpath("//img")
|
87
|
+
images.map{|img| img['src'] }
|
88
|
+
end
|
89
|
+
|
90
|
+
def preferred_child_template_name
|
91
|
+
preferred_option('preferred_child_template_name')
|
92
|
+
end
|
93
|
+
|
94
|
+
def preferred_child_prototype_name
|
95
|
+
preferred_option('preferred_child_prototype_name')
|
96
|
+
end
|
97
|
+
|
98
|
+
def tree_node
|
99
|
+
href = Blacksand::Engine.routes.url_helpers.children_partial_pages_path(parent_id: self.id)
|
100
|
+
|
101
|
+
return {text: self.title, href: href, page_id: self.id} if self.children.count == 0
|
102
|
+
|
103
|
+
# children 多余 15 个且都是叶子节点, 那么子节点不显示
|
104
|
+
if self.children.count >= 15 && self.children.limit(15).all? { |p| p.children.empty? }
|
105
|
+
{
|
106
|
+
text: self.title,
|
107
|
+
href: href,
|
108
|
+
page_id: self.id
|
109
|
+
}
|
110
|
+
else
|
111
|
+
{
|
112
|
+
text: self.title,
|
113
|
+
href: href,
|
114
|
+
page_id: self.id,
|
115
|
+
nodes: self.children.order(:position).map { |p| p.tree_node },
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_properties
|
122
|
+
self.prototype.fields.each do |field|
|
123
|
+
Property.build_property(self, field)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.tree_nodes(page_ids = nil)
|
128
|
+
if page_ids
|
129
|
+
Page.where(id: page_ids).order(:position).map { |p| p.tree_node }
|
130
|
+
else
|
131
|
+
Page.where('parent_id is null').order(:position).map { |p| p.tree_node }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.selectNode(nodes, page_id)
|
136
|
+
nodes.each do |node|
|
137
|
+
if node[:page_id] == page_id
|
138
|
+
node.merge!(state: {selected: true})
|
139
|
+
return
|
140
|
+
end
|
141
|
+
|
142
|
+
selectNode(node[:nodes], page_id) if node[:nodes].present?
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
def self.query_value(name, value)
|
148
|
+
joins(properties: :field).where(fields: {name: name}, properties: {value: value})
|
149
|
+
end
|
150
|
+
|
151
|
+
protected
|
152
|
+
|
153
|
+
def set_owner_for_kindeditor_assets
|
154
|
+
image_assets = image_assets_of_content
|
155
|
+
|
156
|
+
image_assets.each do |asset_name|
|
157
|
+
asset = Kindeditor::Asset.where(asset: asset_name, owner_id: 0).first
|
158
|
+
asset.update(owner_id: self.id, owner_type: self.class.name) if asset.present?
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def clean_unsued_kindeditor_assets
|
163
|
+
image_assets = image_assets_of_content
|
164
|
+
exists_image_assets = self.attachments.to_a.select { |asset| asset.asset_type == 'image' }.map { |a| File.basename(a.asset.path) }
|
165
|
+
|
166
|
+
redundant_image_assets = exists_image_assets - image_assets
|
167
|
+
Kindeditor::Asset.where('asset in (?)', redundant_image_assets).destroy_all
|
168
|
+
end
|
169
|
+
|
170
|
+
# 返回内容中所有上传的图片
|
171
|
+
def image_assets_of_content
|
172
|
+
srcs = all_image_srcs_of_content.select do |src|
|
173
|
+
# 本地上传的文件
|
174
|
+
if src.start_with? "/#{RailsKindeditor.upload_store_dir}"
|
175
|
+
true
|
176
|
+
# 有可能是与存储
|
177
|
+
elsif src.start_with?("http") && URI(src).path.start_with?("/#{RailsKindeditor.upload_store_dir}")
|
178
|
+
true
|
179
|
+
else
|
180
|
+
false
|
181
|
+
end
|
182
|
+
end
|
183
|
+
srcs.map { |src| File.basename(src) }
|
184
|
+
end
|
185
|
+
|
186
|
+
def preferred_option(key)
|
187
|
+
if self.template && self.template.options.present? && self.template.options[key]
|
188
|
+
self.template.options[key]
|
189
|
+
elsif self.prototype && self.prototype.options.present? && self.prototype.options[key]
|
190
|
+
self.prototype.options[key]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Blacksand
|
2
|
+
class Property < ActiveRecord::Base
|
3
|
+
include ActionView::Helpers::TextHelper
|
4
|
+
|
5
|
+
mount_uploader :image, Blacksand::ImageUploader
|
6
|
+
|
7
|
+
# Disable this feature. It's not available in release.
|
8
|
+
# ref: https://github.com/carrierwaveuploader/carrierwave/issues/1545
|
9
|
+
#
|
10
|
+
# mount_uploaders :gallery, ImageUploader
|
11
|
+
|
12
|
+
belongs_to :page
|
13
|
+
belongs_to :field
|
14
|
+
default_scope { order(:field_id) }
|
15
|
+
|
16
|
+
validate :check_field_required
|
17
|
+
|
18
|
+
def check_field_required
|
19
|
+
case (self.field.field_type)
|
20
|
+
when 'image', 'slide' then
|
21
|
+
errors.add(:image, "#{field.description}不能为空") if field.required? && !image.present?
|
22
|
+
when 'gallery' then
|
23
|
+
errors.add(:gallery, "#{field.description}不能为空") if field.required? && !pictures.any?
|
24
|
+
when 'file' then
|
25
|
+
errors.add(:file, "#{field.description}不能为空") if field.required? && !file.present?
|
26
|
+
when 'array' then
|
27
|
+
errors.add(:values, "#{field.description}不能为空") if field.required? && !values.present?
|
28
|
+
else
|
29
|
+
errors.add(:value, "#{field.description}不能为空") if field.required? && !value.present?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def content
|
34
|
+
case (self.field.field_type)
|
35
|
+
when 'textarea'
|
36
|
+
simple_format(self.value)
|
37
|
+
when 'image', 'slide' then
|
38
|
+
self.image
|
39
|
+
when 'gallery' then
|
40
|
+
self.pictures
|
41
|
+
when 'file' then
|
42
|
+
self.file
|
43
|
+
when 'page' then
|
44
|
+
Page.find_by(id: self.value)
|
45
|
+
when 'array' then
|
46
|
+
self.values
|
47
|
+
else
|
48
|
+
self.value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def as_subtype
|
53
|
+
return if self.value.blank?
|
54
|
+
|
55
|
+
case self.field.field_type
|
56
|
+
when 'date' then
|
57
|
+
Date.strptime(self.value, '%F')
|
58
|
+
when 'array' then
|
59
|
+
self.values
|
60
|
+
else
|
61
|
+
self.value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.build_property(page, field)
|
66
|
+
if field.field_type.in? %w[file slide gallery]
|
67
|
+
page.properties.build(field: field, type: "Blacksand::Property::#{field.field_type.capitalize}")
|
68
|
+
elsif field.field_type == 'array'
|
69
|
+
page.properties.build(field: field, type: "Blacksand::Property::As#{field.field_type.capitalize}")
|
70
|
+
else
|
71
|
+
page.properties.build(field: field)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Blacksand
|
2
|
+
class Prototype < ActiveRecord::Base
|
3
|
+
store_accessor :options, :preferred_child_template_name, :preferred_child_prototype_name
|
4
|
+
|
5
|
+
has_many :fields, dependent: :destroy
|
6
|
+
|
7
|
+
accepts_nested_attributes_for :fields
|
8
|
+
|
9
|
+
has_many :pages, dependent: :nullify
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Kindeditor::Asset < ActiveRecord::Base
|
2
|
+
self.table_name = 'kindeditor_assets'
|
3
|
+
mount_uploader :asset, Kindeditor::AssetUploader
|
4
|
+
validates_presence_of :asset
|
5
|
+
before_save :update_asset_attributes
|
6
|
+
|
7
|
+
private
|
8
|
+
def update_asset_attributes
|
9
|
+
if asset.present? && asset_changed?
|
10
|
+
self.file_size = asset.file.size
|
11
|
+
self.file_type = asset.file.content_type
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Blacksand
|
2
|
+
class BaseUploader < ::CarrierWave::Uploader::Base
|
3
|
+
include ::CarrierWave::MiniMagick
|
4
|
+
|
5
|
+
def self.storage_from_config
|
6
|
+
Blacksand.carrierwave_storage
|
7
|
+
end
|
8
|
+
|
9
|
+
storage storage_from_config
|
10
|
+
|
11
|
+
# TODO: config store_dir prefix
|
12
|
+
def store_dir
|
13
|
+
"#{Blacksand.carrierwave_store_dir_prefix}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Blacksand
|
4
|
+
class ImageUploader < BaseUploader
|
5
|
+
|
6
|
+
# Include RMagick or MiniMagick support:
|
7
|
+
# include CarrierWave::RMagick
|
8
|
+
# include CarrierWave::MiniMagick
|
9
|
+
|
10
|
+
# Choose what kind of storage to use for this uploader:
|
11
|
+
# storage :file
|
12
|
+
# storage :fog
|
13
|
+
|
14
|
+
# Override the directory where uploaded files will be stored.
|
15
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
16
|
+
# def store_dir
|
17
|
+
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
18
|
+
# end
|
19
|
+
|
20
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
21
|
+
# def default_url
|
22
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
23
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
24
|
+
#
|
25
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Process files as they are uploaded:
|
29
|
+
# process scale: [200, 300]
|
30
|
+
#
|
31
|
+
# def scale(width, height)
|
32
|
+
# # do something
|
33
|
+
# end
|
34
|
+
|
35
|
+
# Create different versions of your uploaded files:
|
36
|
+
# version :thumb do
|
37
|
+
# process resize_to_fit: [50, 50]
|
38
|
+
# end
|
39
|
+
|
40
|
+
# version :thumb do
|
41
|
+
# process :resize_to_fill => [200, 200]
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# version :thumb_resize_and_pad do
|
45
|
+
# process :resize_and_pad => [200, 200]
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# version :small do
|
49
|
+
# process :resize_to_fill => [280, 150]
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# version :normal do
|
53
|
+
# process :resize_to_fill => [630, 330]
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# version :gallery do
|
57
|
+
# process :resize_to_fill => [1140,525]
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# version :larger do
|
61
|
+
# process :resize_to_fill => [224,148]
|
62
|
+
# end
|
63
|
+
|
64
|
+
|
65
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
66
|
+
# For images you might use something like this:
|
67
|
+
def extension_white_list
|
68
|
+
%w(jpg jpeg gif png)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Override the filename of the uploaded files:
|
72
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
73
|
+
# def filename
|
74
|
+
# "something.jpg" if original_filename
|
75
|
+
# end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Blacksand
|
4
|
+
class SlideImageUploader < BaseUploader
|
5
|
+
|
6
|
+
# Include RMagick or MiniMagick support:
|
7
|
+
# include CarrierWave::RMagick
|
8
|
+
# include CarrierWave::MiniMagick
|
9
|
+
|
10
|
+
# Choose what kind of storage to use for this uploader:
|
11
|
+
# storage :file
|
12
|
+
# storage :fog
|
13
|
+
# set_storage_from_config
|
14
|
+
|
15
|
+
# Override the directory where uploaded files will be stored.
|
16
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
17
|
+
# def store_dir
|
18
|
+
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
22
|
+
# def default_url
|
23
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
24
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
25
|
+
#
|
26
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Process files as they are uploaded:
|
30
|
+
# process scale: [200, 300]
|
31
|
+
#
|
32
|
+
# def scale(width, height)
|
33
|
+
# # do something
|
34
|
+
# end
|
35
|
+
|
36
|
+
# Create different versions of your uploaded files:
|
37
|
+
# version :thumb do
|
38
|
+
# process resize_to_fit: [50, 50]
|
39
|
+
# end
|
40
|
+
|
41
|
+
# version :slide do
|
42
|
+
# process :resize_to_fill => [940, 300]
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# version :slide_1140 do
|
46
|
+
# process :resize_to_fill => [1140, 300]
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# version :slide_with_pad do
|
50
|
+
# process :resize_and_pad => [1140, 300]
|
51
|
+
# end
|
52
|
+
|
53
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
54
|
+
# For images you might use something like this:
|
55
|
+
def extension_white_list
|
56
|
+
%w(jpg jpeg gif png)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Override the filename of the uploaded files:
|
60
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
61
|
+
# def filename
|
62
|
+
# "something.jpg" if original_filename
|
63
|
+
# end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|