ksk 0.2.12 → 0.2.13
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.
- checksums.yaml +4 -4
- data/app/helpers/ksk/frontend_helper.rb +58 -56
- data/app/models/concerns/ksk/asset.rb +102 -0
- data/app/models/concerns/ksk/category.rb +10 -0
- data/{lib/apdown.rb → app/models/concerns/ksk/markdown.rb} +43 -8
- data/app/models/concerns/ksk/navigation.rb +66 -0
- data/app/models/concerns/ksk/navigation_type.rb +8 -0
- data/app/models/concerns/ksk/post.rb +17 -0
- data/app/models/concerns/ksk/preview.rb +19 -0
- data/app/models/concerns/ksk/static.rb +14 -0
- data/app/views/bhf/pages/_navi.html.haml +1 -1
- data/lib/ksk.rb +2 -11
- data/lib/rails/generators/ksk/templates/initializer.rb +1 -1
- metadata +10 -10
- data/lib/actives/asset.rb +0 -107
- data/lib/actives/category.rb +0 -13
- data/lib/actives/navigation.rb +0 -69
- data/lib/actives/navigation_type.rb +0 -11
- data/lib/actives/post.rb +0 -50
- data/lib/actives/preview.rb +0 -23
- data/lib/actives/static.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0903010534dbdb8def81f709cef635d7f00e4400
|
4
|
+
data.tar.gz: 61c55153c9beab9dfdfc368b706357cbabfb8220
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a339a8263f265d4a57025344e23b3e2ad857ec7265d088e9d3f727e5021121581acc9b00b32152e28700cce4bd144cfaa996beed6e25c246e4057d89dba6899
|
7
|
+
data.tar.gz: 08fc5e99264336b12291da3f55a38b49765e87d6cd3a6ba013c6c58c23c172827c678c4d497acb9a62bca620fd4b5c0e6535be345fb97b8d26ce7a5dfb84514c
|
@@ -1,73 +1,75 @@
|
|
1
|
-
module Ksk
|
2
|
-
module FrontendHelper
|
1
|
+
module Ksk::FrontendHelper
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
a += " <li#{active}>#{link}"
|
15
|
-
if active && current_level <= max_level && navi.children.not_hidden.any?
|
16
|
-
a += recursive_navi(navi.children.not_hidden, current_level+1, max_level)
|
17
|
-
end
|
18
|
-
a += '</li> '
|
3
|
+
def recursive_navi(navis, current_level = 0, max_level = 99)
|
4
|
+
a = ' <ul>'
|
5
|
+
navis.each do |navi|
|
6
|
+
active = navi.slug == @slugs[current_level] ? ' class="active"' : nil
|
7
|
+
next unless nt = navi.navigation_type
|
8
|
+
link = if nt.name == 'news'
|
9
|
+
link_to navi.title, posts_path
|
10
|
+
else
|
11
|
+
link_to navi.title, navi.link
|
19
12
|
end
|
20
|
-
a +=
|
13
|
+
a += " <li#{active}>#{link}"
|
14
|
+
if active && current_level <= max_level && navi.children.not_hidden.any?
|
15
|
+
a += recursive_navi(navi.children.not_hidden, current_level+1, max_level)
|
16
|
+
end
|
17
|
+
a += '</li> '
|
21
18
|
end
|
19
|
+
a += '</ul> '
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
markdown.render(text).html_safe
|
27
|
-
end
|
22
|
+
def kskmd(model_instance)
|
23
|
+
mdap(model_instance.content_long, model_instance.assets.only_images, model_instance.assets.only_data_files)
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
26
|
+
def md(text)
|
27
|
+
return '' if text.blank?
|
28
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(), fenced_code_blocks: true, autolink: true)
|
29
|
+
markdown.render(text).html_safe
|
30
|
+
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
def mdap(text, images, data_files)
|
33
|
+
return '' if text.blank?
|
34
|
+
t = place_images(text, images)
|
35
|
+
t = place_data_files(t, data_files)
|
36
|
+
md(t)
|
37
|
+
end
|
38
|
+
|
39
|
+
def place_content(text, files, type, &html)
|
40
|
+
t = text
|
41
|
+
Ksk::Markdown.parse_text(text, type).each do |match|
|
42
|
+
relpace = if asset = files[match[1].to_i-1]
|
43
|
+
html.call(asset, match[2])
|
43
44
|
end
|
44
|
-
t.
|
45
|
+
t = t.gsub(match[0], relpace.to_s)
|
45
46
|
end
|
47
|
+
t.html_safe
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
50
|
+
def place_images(text, images)
|
51
|
+
place_content(text, images, 'img') do |asset, option|
|
52
|
+
c = option || 'thumb'
|
53
|
+
image_tag asset.file.url(c), class: ['uploaded_image', c]
|
52
54
|
end
|
55
|
+
end
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
asset.preview.name
|
64
|
-
end
|
57
|
+
def place_data_files(text, data_files)
|
58
|
+
place_content(text, data_files, 'file') do |asset, option|
|
59
|
+
link_to asset.file.url, title: asset.file.original_filename, class: asset.has_preview? ? :uploaded_file_preview : :uploaded_file do
|
60
|
+
if asset.has_preview?
|
61
|
+
if asset.has_preview_image?
|
62
|
+
t_capition = !asset.preview.name.blank? ? asset.preview.name : t('ksk.asset.file_preview.button.download')
|
63
|
+
image_tag( asset.preview_file.url(:banner) )+
|
64
|
+
"<span>#{t_capition}</span>".html_safe
|
65
65
|
else
|
66
|
-
asset.
|
66
|
+
asset.preview.name
|
67
67
|
end
|
68
|
+
else
|
69
|
+
asset.file_file_name
|
68
70
|
end
|
69
71
|
end
|
70
72
|
end
|
71
|
-
|
72
73
|
end
|
73
|
-
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Ksk::Asset
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
belongs_to :fileable, polymorphic: true
|
6
|
+
|
7
|
+
default_scope -> {order 'position ASC, created_at DESC'}
|
8
|
+
|
9
|
+
has_one :preview
|
10
|
+
before_create :set_last_position
|
11
|
+
|
12
|
+
after_initialize :resize_attr_accessors
|
13
|
+
before_save :crop_thumbs, if: :cropping?
|
14
|
+
|
15
|
+
IMGTYPE = ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/tif', 'image/gif']
|
16
|
+
do_not_validate_attachment_file_type :file
|
17
|
+
|
18
|
+
scope :only_images, -> {where(file_content_type: IMGTYPE)}
|
19
|
+
scope :first_image, -> {only_images.limit(1)}
|
20
|
+
scope :other_images, -> {only_images.offset(1)}
|
21
|
+
|
22
|
+
scope :only_data_files, -> {where('file_content_type not in (?)', IMGTYPE)}
|
23
|
+
scope :first_data_files, -> {only_data_files.limit(1)}
|
24
|
+
|
25
|
+
before_file_post_process :allow_only_images
|
26
|
+
end
|
27
|
+
|
28
|
+
def resize_attr_accessors
|
29
|
+
file.styles.each_pair do |style, meta|
|
30
|
+
self.class.send(:attr_accessor, "#{style}_x")
|
31
|
+
self.class.send(:attr_accessor, "#{style}_y")
|
32
|
+
self.class.send(:attr_accessor, "#{style}_w")
|
33
|
+
self.class.send(:attr_accessor, "#{style}_h")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def cropping?
|
38
|
+
needs_crop = false
|
39
|
+
file.styles.each_pair do |style, meta|
|
40
|
+
if !needs_crop
|
41
|
+
needs_crop = cords_set?(style)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
needs_crop
|
45
|
+
end
|
46
|
+
|
47
|
+
def cords_set?(style)
|
48
|
+
!send("#{style}_x").blank? && !send("#{style}_y").blank? && !send("#{style}_w").blank? && !send("#{style}_h").blank?
|
49
|
+
end
|
50
|
+
|
51
|
+
def crop_thumbs
|
52
|
+
file.styles.each_pair do |style, meta|
|
53
|
+
if cords_set?(style)
|
54
|
+
resize_banner style, [send("#{style}_x"), send("#{style}_y"), send("#{style}_w"), send("#{style}_h")], meta.attachment.options[:styles][style][0]
|
55
|
+
send("#{style}_x=", false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
file.save
|
59
|
+
file.instance.save
|
60
|
+
end
|
61
|
+
|
62
|
+
def resize_banner(name, cords, resize)
|
63
|
+
file.queued_for_write[name] = Paperclip.processor(:ksk_crop).make(file, cords, file)
|
64
|
+
style = Paperclip::Style.new(name, [resize, :jpg], file)
|
65
|
+
file.queued_for_write[name] = Paperclip.processor(:thumbnail).make(file.queued_for_write[name], style.processor_options, file.queued_for_write[name])
|
66
|
+
file.queued_for_write[name] = Paperclip.io_adapters.for(file.queued_for_write[name])
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def allow_only_images
|
71
|
+
if !(file.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$})
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def is_image?
|
77
|
+
IMGTYPE.include?(file.content_type)
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_preview?
|
81
|
+
preview && (preview.assets.any? || !preview.name.blank?)
|
82
|
+
end
|
83
|
+
|
84
|
+
def has_preview_image?
|
85
|
+
preview.assets.any? and preview.assets.first.file
|
86
|
+
end
|
87
|
+
|
88
|
+
def preview_file
|
89
|
+
if has_preview?
|
90
|
+
preview.assets.first.file
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_bhf_s
|
95
|
+
"ID: #{id} - Name: #{file_file_name}"
|
96
|
+
end
|
97
|
+
|
98
|
+
def set_last_position
|
99
|
+
self.position = self.class.where(fileable_id: self.fileable_id).count + 1
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
/(\{#{type}_(\d{1,2})_?(\w+)?\})/i
|
5
|
-
end
|
6
|
-
|
1
|
+
module Ksk::Markdown
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
7
4
|
def text_used_content(type)
|
8
|
-
(
|
5
|
+
Ksk::Markdown.parse_text(markdown_text, type).each_with_object([]) do |match, used_numbers|
|
9
6
|
used_numbers << match[1].to_i
|
10
7
|
end
|
11
8
|
end
|
@@ -28,7 +25,7 @@ module Apdown
|
|
28
25
|
end
|
29
26
|
|
30
27
|
def text_unused_images
|
31
|
-
text_unused_content(assets.only_images, 'img', respond_to?(:
|
28
|
+
text_unused_content(assets.only_images, 'img', respond_to?(:markdown_preselect) && markdown_preselect || [])
|
32
29
|
end
|
33
30
|
|
34
31
|
def text_used_data_files
|
@@ -39,4 +36,42 @@ module Apdown
|
|
39
36
|
text_unused_content(assets.only_data_files, 'file')
|
40
37
|
end
|
41
38
|
|
39
|
+
|
40
|
+
def markdown_text
|
41
|
+
content
|
42
|
+
end
|
43
|
+
|
44
|
+
def content_long
|
45
|
+
"#{intro} #{hidden_text}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def content_short
|
49
|
+
intro
|
50
|
+
end
|
51
|
+
|
52
|
+
def intro
|
53
|
+
split_content[0]
|
54
|
+
end
|
55
|
+
|
56
|
+
def hidden_text
|
57
|
+
split_content[1]
|
58
|
+
end
|
59
|
+
|
60
|
+
def split_content
|
61
|
+
return [] if read_attribute(:content).blank?
|
62
|
+
read_attribute(:content).split('@@@')
|
63
|
+
end
|
64
|
+
|
65
|
+
def content_has_more?
|
66
|
+
!hidden_text.blank?
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def self.parse_regex(type)
|
71
|
+
/(\{#{type}_(\d{1,2})_?(\w+)?\})/i
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.parse_text(text, type)
|
75
|
+
text.to_s.scan(parse_regex(type))
|
76
|
+
end
|
42
77
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Ksk::Navigation
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
validates_uniqueness_of :slug
|
6
|
+
validates_presence_of :static
|
7
|
+
|
8
|
+
before_validation :static_setter
|
9
|
+
|
10
|
+
default_scope -> {order 'position ASC, created_at DESC'}
|
11
|
+
|
12
|
+
belongs_to :static
|
13
|
+
belongs_to :navigation_type
|
14
|
+
belongs_to :parent, foreign_key: 'parent_id', class_name: 'Navigation'
|
15
|
+
has_many :children, foreign_key: 'parent_id', class_name: 'Navigation', dependent: :delete_all
|
16
|
+
|
17
|
+
scope :top_level, -> {where(parent_id: 0)}
|
18
|
+
|
19
|
+
scope :not_hidden, -> {where(hidden: false)}
|
20
|
+
|
21
|
+
before_save :set_slug, :set_link
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def set_slug
|
26
|
+
return if !slug.blank?
|
27
|
+
write_attribute(:slug, title.to_url)
|
28
|
+
end
|
29
|
+
|
30
|
+
def static_setter
|
31
|
+
write_attribute(:static_id, (self.static && self.static.id) || ::Static.all.first.id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_link
|
35
|
+
write_attribute(:link, get_link)
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_link(x = '')
|
39
|
+
a = '/'+slug+x
|
40
|
+
if parent
|
41
|
+
a = parent.get_link(a)
|
42
|
+
end
|
43
|
+
a
|
44
|
+
end
|
45
|
+
|
46
|
+
module ClassMethods
|
47
|
+
def sort_items(ids)
|
48
|
+
ids.each_pair do |i, id|
|
49
|
+
find(id).update_attribute(:position, i.to_i)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def show_bread_crum_desc(navi)
|
54
|
+
a = [navi]
|
55
|
+
if navi.parent
|
56
|
+
a << show_bread_crum_desc(navi.parent)
|
57
|
+
end
|
58
|
+
a.flatten
|
59
|
+
end
|
60
|
+
|
61
|
+
def show_bread_crum(navi)
|
62
|
+
show_bread_crum_desc(navi).reverse
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ksk::Post
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include Ksk::Markdown
|
6
|
+
|
7
|
+
belongs_to :category
|
8
|
+
has_many :assets, as: :fileable
|
9
|
+
accepts_nested_attributes_for :assets, allow_destroy: true
|
10
|
+
|
11
|
+
scope :all_posts, -> {except(:where)}
|
12
|
+
scope :top, -> {where(top_news: true)}
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Ksk::Preview
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
belongs_to :asset
|
6
|
+
has_many :assets, :as => :fileable
|
7
|
+
|
8
|
+
accepts_nested_attributes_for :assets, allow_destroy: true
|
9
|
+
|
10
|
+
validates_presence_of :asset_id
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def file_assets
|
15
|
+
assets.only_data_files
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Ksk::Static
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include Ksk::Markdown
|
6
|
+
|
7
|
+
has_one :navigation
|
8
|
+
has_many :assets, as: :fileable
|
9
|
+
# TODO: needs on_delete hook to destroy navigation if Navigation is availible for this object
|
10
|
+
|
11
|
+
accepts_nested_attributes_for :assets, allow_destroy: true
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
a = "\n <#{ul}#{first_wrap}>\n"
|
4
4
|
navis.each do |navi|
|
5
5
|
x = link_to 'edit', edit_entry_path('navigation', navi), class: 'edit icon'
|
6
|
-
y = link_to 'delete', entry_path('navigation', navi), :
|
6
|
+
y = link_to 'delete', entry_path('navigation', navi), method: :delete, confirm: t('bhf.helpers.promts.confirm'), class: 'delete icon'
|
7
7
|
a += " <li id='navigation_#{navi.id}'><div><span class='title'>#{navi.title}</span> <span class='links'>#{x} #{y}</span></div>"
|
8
8
|
if current_level <= max_level and navi.children.any?
|
9
9
|
a += p_recursive_navi(navi.children, current_level+1, max_level, ul)
|
data/lib/ksk.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'stringex'
|
2
|
-
|
3
1
|
module Ksk
|
4
2
|
class Engine < Rails::Engine
|
5
3
|
|
@@ -8,7 +6,7 @@ module Ksk
|
|
8
6
|
config.bhf.css << 'ksk/application'
|
9
7
|
config.bhf.js << 'ksk/application'
|
10
8
|
|
11
|
-
initializer 'ksk.
|
9
|
+
initializer 'ksk.helper' do
|
12
10
|
ActiveSupport.on_load :action_controller do
|
13
11
|
helper Ksk::FrontendHelper
|
14
12
|
end
|
@@ -17,13 +15,6 @@ module Ksk
|
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
20
|
-
require '
|
21
|
-
require 'actives/asset'
|
22
|
-
require 'actives/category'
|
23
|
-
require 'actives/navigation'
|
24
|
-
require 'actives/navigation_type'
|
25
|
-
require 'actives/post'
|
26
|
-
require 'actives/preview'
|
27
|
-
require 'actives/static'
|
18
|
+
require 'stringex'
|
28
19
|
require 'paperclip/processor'
|
29
20
|
require 'paperclip_processors/ksk_crop'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ksk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Pawlik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bhf
|
@@ -65,6 +65,14 @@ files:
|
|
65
65
|
- app/assets/stylesheets/ksk/application.css.sass
|
66
66
|
- app/controllers/ksk/navigations_controller.rb
|
67
67
|
- app/helpers/ksk/frontend_helper.rb
|
68
|
+
- app/models/concerns/ksk/asset.rb
|
69
|
+
- app/models/concerns/ksk/category.rb
|
70
|
+
- app/models/concerns/ksk/markdown.rb
|
71
|
+
- app/models/concerns/ksk/navigation.rb
|
72
|
+
- app/models/concerns/ksk/navigation_type.rb
|
73
|
+
- app/models/concerns/ksk/post.rb
|
74
|
+
- app/models/concerns/ksk/preview.rb
|
75
|
+
- app/models/concerns/ksk/static.rb
|
68
76
|
- app/views/bhf/entries/form/column/_crop_thumbs.html.haml
|
69
77
|
- app/views/bhf/entries/form/column/_file.html.haml
|
70
78
|
- app/views/bhf/entries/form/column/_select_file_assets.html.haml
|
@@ -76,14 +84,6 @@ files:
|
|
76
84
|
- config/locales/de.yml
|
77
85
|
- config/locales/en.yml
|
78
86
|
- config/routes.rb
|
79
|
-
- lib/actives/asset.rb
|
80
|
-
- lib/actives/category.rb
|
81
|
-
- lib/actives/navigation.rb
|
82
|
-
- lib/actives/navigation_type.rb
|
83
|
-
- lib/actives/post.rb
|
84
|
-
- lib/actives/preview.rb
|
85
|
-
- lib/actives/static.rb
|
86
|
-
- lib/apdown.rb
|
87
87
|
- lib/ksk.rb
|
88
88
|
- lib/paperclip_processors/ksk_crop.rb
|
89
89
|
- lib/rails/generators/ksk/templates/initializer.rb
|
data/lib/actives/asset.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
module Ksk
|
2
|
-
module Asset
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
self.table_name = 'assets'
|
7
|
-
|
8
|
-
belongs_to :fileable, polymorphic: true
|
9
|
-
|
10
|
-
default_scope -> {order 'position ASC, created_at DESC'}
|
11
|
-
|
12
|
-
has_one :preview
|
13
|
-
before_create :set_last_position
|
14
|
-
|
15
|
-
after_initialize :resize_attr_accessors
|
16
|
-
before_save :crop_thumbs, if: :cropping?
|
17
|
-
|
18
|
-
IMGTYPE = ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png', 'image/tif', 'image/gif']
|
19
|
-
do_not_validate_attachment_file_type :file
|
20
|
-
|
21
|
-
scope :only_images, -> {where(file_content_type: IMGTYPE)}
|
22
|
-
scope :first_image, -> {only_images.limit(1)}
|
23
|
-
scope :other_images, -> {only_images.offset(1)}
|
24
|
-
|
25
|
-
scope :only_data_files, -> {where(['file_content_type not in (?)', IMGTYPE])}
|
26
|
-
scope :first_data_files, -> {only_data_files.limit(1)}
|
27
|
-
|
28
|
-
before_file_post_process :allow_only_images
|
29
|
-
end
|
30
|
-
|
31
|
-
def resize_attr_accessors
|
32
|
-
file.styles.each_pair do |style, meta|
|
33
|
-
self.class.send(:attr_accessor, "#{style}_x")
|
34
|
-
self.class.send(:attr_accessor, "#{style}_y")
|
35
|
-
self.class.send(:attr_accessor, "#{style}_w")
|
36
|
-
self.class.send(:attr_accessor, "#{style}_h")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def cropping?
|
41
|
-
needs_crop = false
|
42
|
-
file.styles.each_pair do |style, meta|
|
43
|
-
if !needs_crop
|
44
|
-
needs_crop = cords_set?(style)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
needs_crop
|
48
|
-
end
|
49
|
-
|
50
|
-
def cords_set?(style)
|
51
|
-
!send("#{style}_x").blank? && !send("#{style}_y").blank? && !send("#{style}_w").blank? && !send("#{style}_h").blank?
|
52
|
-
end
|
53
|
-
|
54
|
-
def crop_thumbs
|
55
|
-
file.styles.each_pair do |style, meta|
|
56
|
-
if cords_set?(style)
|
57
|
-
resize_banner style, [send("#{style}_x"), send("#{style}_y"), send("#{style}_w"), send("#{style}_h")], meta.attachment.options[:styles][style][0]
|
58
|
-
send("#{style}_x=", false)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
file.save
|
62
|
-
file.instance.save
|
63
|
-
end
|
64
|
-
|
65
|
-
def resize_banner(name, cords, resize)
|
66
|
-
file.queued_for_write[name] = Paperclip.processor(:ksk_crop).make(file, cords, file)
|
67
|
-
style = Paperclip::Style.new(name, [resize, :jpg], file)
|
68
|
-
file.queued_for_write[name] = Paperclip.processor(:thumbnail).make(file.queued_for_write[name], style.processor_options, file.queued_for_write[name])
|
69
|
-
file.queued_for_write[name] = Paperclip.io_adapters.for(file.queued_for_write[name])
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def allow_only_images
|
74
|
-
if !(file.content_type =~ %r{^(image|(x-)?application)/(x-png|pjpeg|jpeg|jpg|png|gif)$})
|
75
|
-
return false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def is_image?
|
80
|
-
IMGTYPE.include?(file.content_type)
|
81
|
-
end
|
82
|
-
|
83
|
-
def has_preview?
|
84
|
-
preview && (preview.assets.any? || !preview.name.blank?)
|
85
|
-
end
|
86
|
-
|
87
|
-
def has_preview_image?
|
88
|
-
preview.assets.any? and preview.assets.first.file
|
89
|
-
end
|
90
|
-
|
91
|
-
def preview_file
|
92
|
-
if has_preview?
|
93
|
-
preview.assets.first.file
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def to_bhf_s
|
98
|
-
"ID: #{id} - Name: #{file_file_name}"
|
99
|
-
end
|
100
|
-
|
101
|
-
def set_last_position
|
102
|
-
self.position = self.class.where(fileable_id: self.fileable_id).count+1
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
data/lib/actives/category.rb
DELETED
data/lib/actives/navigation.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Ksk
|
2
|
-
module Navigation
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
self.table_name = 'navigations'
|
7
|
-
validates_uniqueness_of :slug
|
8
|
-
validates_presence_of :static
|
9
|
-
|
10
|
-
before_validation :static_setter
|
11
|
-
|
12
|
-
default_scope -> {order 'position ASC, created_at DESC'}
|
13
|
-
|
14
|
-
belongs_to :static
|
15
|
-
belongs_to :navigation_type
|
16
|
-
belongs_to :parent, foreign_key: 'parent_id', class_name: 'Navigation'
|
17
|
-
has_many :children, foreign_key: 'parent_id', class_name: 'Navigation', dependent: :delete_all
|
18
|
-
|
19
|
-
scope :top_level, -> {where(parent_id: 0)}
|
20
|
-
|
21
|
-
scope :not_hidden, -> {where(hidden: false)}
|
22
|
-
|
23
|
-
before_save :set_slug, :set_link
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def set_slug
|
28
|
-
return if !slug.blank?
|
29
|
-
write_attribute(:slug, title.to_url)
|
30
|
-
end
|
31
|
-
|
32
|
-
def static_setter
|
33
|
-
write_attribute(:static_id, (self.static && self.static.id) || ::Static.all.first.id)
|
34
|
-
end
|
35
|
-
|
36
|
-
def set_link
|
37
|
-
write_attribute(:link, get_link)
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_link(x = '')
|
41
|
-
a = '/'+slug+x
|
42
|
-
if parent
|
43
|
-
a = parent.get_link(a)
|
44
|
-
end
|
45
|
-
a
|
46
|
-
end
|
47
|
-
|
48
|
-
module ClassMethods
|
49
|
-
def sort_items(ids)
|
50
|
-
ids.each_pair do |i, id|
|
51
|
-
find(id).update_attribute(:position, i.to_i)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def show_bread_crum_desc(navi)
|
56
|
-
a = [navi]
|
57
|
-
if navi.parent
|
58
|
-
a << show_bread_crum_desc(navi.parent)
|
59
|
-
end
|
60
|
-
a.flatten
|
61
|
-
end
|
62
|
-
|
63
|
-
def show_bread_crum(navi)
|
64
|
-
show_bread_crum_desc(navi).reverse
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
data/lib/actives/post.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Ksk
|
2
|
-
module Post
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
self.table_name = 'posts'
|
7
|
-
|
8
|
-
include Apdown
|
9
|
-
|
10
|
-
belongs_to :category
|
11
|
-
has_many :assets, as: :fileable
|
12
|
-
accepts_nested_attributes_for :assets, allow_destroy: true
|
13
|
-
|
14
|
-
scope :all_posts, -> {except(:where)}
|
15
|
-
scope :top, -> {where(top_news: true)}
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def apdown_text
|
21
|
-
content
|
22
|
-
end
|
23
|
-
|
24
|
-
def content_long
|
25
|
-
"#{intro} #{hidden_text}"
|
26
|
-
end
|
27
|
-
|
28
|
-
def content_short
|
29
|
-
intro
|
30
|
-
end
|
31
|
-
|
32
|
-
def intro
|
33
|
-
split_content[0]
|
34
|
-
end
|
35
|
-
|
36
|
-
def hidden_text
|
37
|
-
split_content[1]
|
38
|
-
end
|
39
|
-
|
40
|
-
def split_content
|
41
|
-
return [] if read_attribute(:content).blank?
|
42
|
-
read_attribute(:content).split('@@@')
|
43
|
-
end
|
44
|
-
|
45
|
-
def content_has_more?
|
46
|
-
!hidden_text.blank?
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/lib/actives/preview.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Ksk
|
2
|
-
module Preview
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
self.table_name = 'previews'
|
7
|
-
|
8
|
-
belongs_to :asset
|
9
|
-
has_many :assets, :as => :fileable
|
10
|
-
|
11
|
-
accepts_nested_attributes_for :assets, allow_destroy: true
|
12
|
-
|
13
|
-
validates_presence_of :asset_id
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
def file_assets
|
18
|
-
assets.only_data_files
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/lib/actives/static.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Ksk
|
2
|
-
module Static
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
self.table_name = 'statics'
|
7
|
-
|
8
|
-
include Apdown
|
9
|
-
|
10
|
-
has_one :navigation
|
11
|
-
has_many :assets, as: :fileable
|
12
|
-
# TODO: needs on_delete hook to destroy navigation if Navigation is availible for this object
|
13
|
-
|
14
|
-
accepts_nested_attributes_for :assets, allow_destroy: true
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|