ksk 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68bd7450c36e8b17bd2ae84f6dcd81f149ed3ec8
4
- data.tar.gz: b98ff22ddc2767a0e90786d78e49ffc729524108
3
+ metadata.gz: 0903010534dbdb8def81f709cef635d7f00e4400
4
+ data.tar.gz: 61c55153c9beab9dfdfc368b706357cbabfb8220
5
5
  SHA512:
6
- metadata.gz: 4cef8761d70efbfc139ea80cbf3d06a62e0d4970569dcb49b17a59f56b07fb01cf02a135490a177d80d7e585fefa26db482758f70650669bdcd28b0627df5125
7
- data.tar.gz: 61a0c2a6f2dbd80d5e3f41aba550277f3e522a3c1ea50e6cd6f1bcc2753560447cd6b6a299f7fe6652999a80acf62bd7756f2545661477c8577503624e309b63
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
- def recursive_navi(navis, current_level = 0, max_level = 99)
5
- a = ' <ul>'
6
- navis.each do |navi|
7
- active = navi.slug == @slugs[current_level] ? ' class="active"' : nil
8
- next unless nt = navi.navigation_type
9
- link = if nt.name == 'news'
10
- link_to navi.title, posts_path
11
- else
12
- link_to navi.title, navi.link
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 += '</ul> '
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
- def md(text)
24
- return '' if text.blank?
25
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(), fenced_code_blocks: true, autolink: true)
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
- def mdap(text, images, data_files)
30
- return '' if text.blank?
31
- t = place_images(text, images)
32
- t = place_data_files(t, data_files)
33
- md(t)
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
- def place_content(text, files, type, &html)
37
- t = text
38
- (text || '').scan(Apdown.parse_regex(type)).each do |match|
39
- relpace = if asset = files[match[1].to_i-1]
40
- html.call(asset, match[2])
41
- end
42
- t = t.gsub(match[0], relpace.to_s)
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.html_safe
45
+ t = t.gsub(match[0], relpace.to_s)
45
46
  end
47
+ t.html_safe
48
+ end
46
49
 
47
- def place_images(text, images)
48
- place_content(text, images, 'img') do |asset, option|
49
- c = option || 'thumb'
50
- image_tag asset.file.url(c), class: ['uploaded_image', c]
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
- def place_data_files(text, data_files)
55
- place_content(text, data_files, 'file') do |asset, option|
56
- link_to asset.file.url, title: asset.file.original_filename, class: asset.has_preview? ? :uploaded_file_preview : :uploaded_file do
57
- if asset.has_preview?
58
- if asset.has_preview_image?
59
- t_capition = !asset.preview.name.blank? ? asset.preview.name : t('ksk.asset.file_preview.button.download')
60
- image_tag( asset.preview_file.url(:banner) )+
61
- "<span>#{t_capition}</span>".html_safe
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.file_file_name
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
- end
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
@@ -0,0 +1,10 @@
1
+ module Ksk::Category
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :posts
6
+
7
+ validates_length_of :title, minimum: 3
8
+ end
9
+
10
+ end
@@ -1,11 +1,8 @@
1
- module Apdown
2
-
3
- def self.parse_regex(type)
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
- (apdown_text || '').scan(Apdown.parse_regex(type)).each_with_object([]) do |match, used_numbers|
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?(:apdown_preselect) && apdown_preselect || [])
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,8 @@
1
+ module Ksk::NavigationType
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_many :navigations
6
+ end
7
+
8
+ 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), :method => :delete, :confirm => t('bhf.helpers.promts.confirm'), class: 'delete icon'
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.action_controller' do |app|
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 'apdown'
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'
@@ -1,6 +1,6 @@
1
1
  module Ksk
2
2
  class Engine < Rails::Engine
3
-
3
+
4
4
 
5
5
  end
6
6
  end
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.12
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-05-26 00:00:00.000000000 Z
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
-
@@ -1,13 +0,0 @@
1
- module Ksk
2
- module Category
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- self.table_name = 'categories'
7
- has_many :posts
8
-
9
- validates_length_of :title, :minimum => 3
10
- end
11
-
12
- end
13
- end
@@ -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
@@ -1,11 +0,0 @@
1
- module Ksk
2
- module NavigationType
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- self.table_name = 'navigation_types'
7
- has_many :navigations
8
- end
9
-
10
- end
11
- 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
@@ -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
@@ -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