c80_news_tz 0.1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +81 -0
  8. data/Rakefile +1 -0
  9. data/app/admin/c80_news_tz/compaines.rb +131 -0
  10. data/app/admin/c80_news_tz/facts.rb +110 -0
  11. data/app/admin/c80_news_tz/issues.rb +60 -0
  12. data/app/admin/c80_news_tz/notices.rb +115 -0
  13. data/app/admin/c80_news_tz/rubrics.rb +45 -0
  14. data/app/assets/images/c80_news_tz/.keep +0 -0
  15. data/app/assets/javascripts/c80_news_tz/application.js.coffee +1 -0
  16. data/app/assets/javascripts/c80_news_tz/backend/collapsable-groups.js +22 -0
  17. data/app/assets/javascripts/c80_news_tz/backend.js.coffee +1 -0
  18. data/app/assets/javascripts/c80_news_tz/frontend/facts_ajax.js +68 -0
  19. data/app/assets/javascripts/c80_news_tz/frontend/facts_wookmark.js +10 -0
  20. data/app/assets/stylesheets/c80_news_tz/application.scss +5 -0
  21. data/app/assets/stylesheets/c80_news_tz/backend/collapsed.scss +49 -0
  22. data/app/assets/stylesheets/c80_news_tz/backend/companies.scss +98 -0
  23. data/app/assets/stylesheets/c80_news_tz/backend/notices.scss +68 -0
  24. data/app/assets/stylesheets/c80_news_tz/backend.scss +1 -0
  25. data/app/assets/stylesheets/c80_news_tz/facts_wookmark.scss +27 -0
  26. data/app/controllers/c80_news_tz/application_controller.rb +10 -0
  27. data/app/helpers/c80_news_tz/application_helper.rb +41 -0
  28. data/app/models/c80_news_tz/adress.rb +5 -0
  29. data/app/models/c80_news_tz/company.rb +42 -0
  30. data/app/models/c80_news_tz/cphoto.rb +38 -0
  31. data/app/models/c80_news_tz/fact.rb +44 -0
  32. data/app/models/c80_news_tz/fact_validator.rb +19 -0
  33. data/app/models/c80_news_tz/fphoto.rb +44 -0
  34. data/app/models/c80_news_tz/gallery.rb +12 -0
  35. data/app/models/c80_news_tz/gphoto.rb +6 -0
  36. data/app/models/c80_news_tz/issue.rb +11 -0
  37. data/app/models/c80_news_tz/notice.rb +41 -0
  38. data/app/models/c80_news_tz/nphoto.rb +38 -0
  39. data/app/models/c80_news_tz/pdf.rb +6 -0
  40. data/app/models/c80_news_tz/prop.rb +5 -0
  41. data/app/models/c80_news_tz/rubric.rb +25 -0
  42. data/app/models/c80_news_tz/rubric_validator.rb +18 -0
  43. data/app/uploaders/c80_news_tz/cphoto_uploader.rb +88 -0
  44. data/app/uploaders/c80_news_tz/fphoto_uploader.rb +93 -0
  45. data/app/uploaders/c80_news_tz/gphoto_uploader.rb +61 -0
  46. data/app/uploaders/c80_news_tz/nphoto_uploader.rb +88 -0
  47. data/app/uploaders/c80_news_tz/pdf_uploader.rb +27 -0
  48. data/app/views/c80_news_tz/application/guru.js.erb +10 -0
  49. data/app/views/layouts/c80_news_tz/application.html.erb +14 -0
  50. data/app/views/shared/_fact.html.erb +13 -0
  51. data/app/views/shared/_news_block.html.erb +8 -0
  52. data/app/views/shared/_news_list.html.erb +12 -0
  53. data/bin/console +14 -0
  54. data/bin/setup +7 -0
  55. data/c80_news_tz.gemspec +27 -0
  56. data/config/locales/ru.yml +70 -0
  57. data/config/routes.rb +4 -0
  58. data/db/migrate/20151129000045_create_rubrics.rb +11 -0
  59. data/db/migrate/20151213202020_create_facts.rb +16 -0
  60. data/db/migrate/20151213202021_create_join_table_facts_rubrics.rb +12 -0
  61. data/db/migrate/20151213203030_create_fphotos.rb +11 -0
  62. data/db/migrate/20151214133030_create_props.rb +9 -0
  63. data/db/migrate/20160226131111_create_issues.rb +9 -0
  64. data/db/migrate/20160226131112_create_join_table_facts_issues.rb +12 -0
  65. data/db/migrate/20160226131313_create_pdfs.rb +11 -0
  66. data/db/migrate/20160226142022_create_companies.rb +12 -0
  67. data/db/migrate/20160226142023_create_join_table_companies_facts.rb +12 -0
  68. data/db/migrate/20160226143300_create_cphotos.rb +10 -0
  69. data/db/migrate/20160227113411_create_notices.rb +13 -0
  70. data/db/migrate/20160227113412_create_join_table_companies_notices.rb +12 -0
  71. data/db/migrate/20160227114040_create_adresses.rb +21 -0
  72. data/db/migrate/20160227121414_create_galleries.rb +12 -0
  73. data/db/migrate/20160227121415_create_gphotos.rb +12 -0
  74. data/db/migrate/20160227121416_create_nphotos.rb +10 -0
  75. data/db/seeds/19_fill_news_props.rb.example +6 -0
  76. data/db/seeds/20_fill_rubrics.rb.example +10 -0
  77. data/db/seeds/21_fill_facts.rb.example +17 -0
  78. data/db/seeds/22_fill_companies.rb.example +49 -0
  79. data/db/seeds/23_fill_issues.rb.example +19 -0
  80. data/db/seeds/24_fill_notices.rb.example +46 -0
  81. data/lib/c80_news_tz/engine.rb +23 -0
  82. data/lib/c80_news_tz/version.rb +3 -0
  83. data/lib/c80_news_tz.rb +5 -0
  84. data/seeds.sh.example +2 -0
  85. metadata +197 -0
@@ -0,0 +1,18 @@
1
+ module C80NewsTz
2
+ class RubricValidator < ActiveModel::Validator
3
+ def validate(record)
4
+ puts '<RubricValidator.validate>'
5
+
6
+ if record.title.blank?
7
+ record.errors[:title] = 'Укажите, пожалуйста, название рубрики'
8
+ else
9
+ may_be_pages = Rubric.where(:title => record.title)
10
+ # Rails.logger.info("<RubricValidator.validate> #{may_be_pages[0].id} vs #{record.id}")
11
+ if may_be_pages.count > 0 && may_be_pages[0].id != record.id
12
+ record.errors[:title] = 'Рубрика с таким названием уже существует'
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,88 @@
1
+ module C80NewsTz
2
+ class CphotoUploader < CarrierWave::Uploader::Base
3
+
4
+ include CarrierWave::MiniMagick
5
+
6
+ storage :file
7
+
8
+ # При загрузке картинок генерим два thumb:
9
+ # - thumb_big (resize_to_limit),
10
+ # - thumb_small (resize_to_limit: w = page_content*1/3).
11
+
12
+ version :thumb_big do
13
+ process :resize_to_limit_big
14
+ end
15
+
16
+ version :thumb_small do
17
+ process :resize_to_limit_small
18
+ end
19
+
20
+ version :thumb_preview do
21
+ process :resize_to_fill => [229, 152]
22
+ end
23
+
24
+ def store_dir
25
+ "uploads/companies/#{format("%2d", model.company_id)}"
26
+ end
27
+
28
+ def extension_white_list
29
+ %w(jpg jpeg gif png)
30
+ end
31
+
32
+ def filename
33
+ if original_filename
34
+ "photo_#{secure_token(4)}.#{file.extension}"
35
+ end
36
+ end
37
+
38
+ protected
39
+ def secure_token(length=16)
40
+ var = :"@#{mounted_as}_secure_token"
41
+ model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
42
+ end
43
+
44
+
45
+ def resize_to_limit_big
46
+ # puts "<PageArtUploader.resize_to_limit_big>"
47
+ manipulate! do |img|
48
+
49
+ w = SiteProp.first.page_content_width
50
+ h = calc_height_of_image(w)
51
+
52
+ img.resize "#{w}x#{h}>"
53
+ img = yield(img) if block_given?
54
+ img
55
+
56
+ end
57
+ end
58
+
59
+ def resize_to_limit_small
60
+ # puts "<PageArtUploader.resize_to_limit_small>"
61
+ manipulate! do |img|
62
+
63
+ w = SiteProp.first.page_content_width/3
64
+ h = calc_height_of_image(w)
65
+
66
+ img.resize "#{w}x#{h}>"
67
+ img = yield(img) if block_given?
68
+ img
69
+
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def calc_height_of_image(w)
76
+ model_image = ::MiniMagick::Image.open(model.image.current_path)
77
+ calc_height(w, model_image["width"], model_image["height"])
78
+ end
79
+
80
+ # подгоняем по ширине, рассчитываем высоту
81
+ def calc_height(width, original_w, original_h)
82
+ k = width.to_f/original_w
83
+ original_h * k
84
+ end
85
+
86
+
87
+ end
88
+ end
@@ -0,0 +1,93 @@
1
+ module C80NewsTz
2
+ class FphotoUploader < CarrierWave::Uploader::Base
3
+
4
+ # NOTE:: ~FphotoUploader,PageArtUploader,BaseArtUploader~
5
+ # NOTE:: содержит много повторяющегося кода
6
+ # NOTE:: т.к. не прокатило наследование
7
+ # NOTE:: от BaseArtUploader: не переопределяется def store_dir
8
+
9
+ include CarrierWave::MiniMagick
10
+
11
+ storage :file
12
+
13
+ # При загрузке картинок генерим два thumb:
14
+ # - thumb_big (resize_to_limit),
15
+ # - thumb_small (resize_to_limit: w = page_content*1/3).
16
+
17
+ version :thumb_big do
18
+ process :resize_to_limit_big
19
+ end
20
+
21
+ version :thumb_small do
22
+ process :resize_to_limit_small
23
+ end
24
+
25
+ version :thumb_preview do
26
+ process :resize_to_fill => [229, 152]
27
+ end
28
+
29
+ def store_dir
30
+ "uploads/news/#{format("%2d", model.fact_id)}"
31
+ end
32
+
33
+ def extension_white_list
34
+ %w(jpg jpeg gif png)
35
+ end
36
+
37
+ def filename
38
+ if original_filename
39
+ "photo_#{secure_token(4)}.#{file.extension}"
40
+ end
41
+ end
42
+
43
+ protected
44
+ def secure_token(length=16)
45
+ var = :"@#{mounted_as}_secure_token"
46
+ model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
47
+ end
48
+
49
+
50
+ def resize_to_limit_big
51
+ # puts "<PageArtUploader.resize_to_limit_big>"
52
+ manipulate! do |img|
53
+
54
+ w = SiteProp.first.page_content_width
55
+ h = calc_height_of_image(w)
56
+
57
+ img.resize "#{w}x#{h}>"
58
+ img = yield(img) if block_given?
59
+ img
60
+
61
+ end
62
+ end
63
+
64
+ def resize_to_limit_small
65
+ # puts "<PageArtUploader.resize_to_limit_small>"
66
+ manipulate! do |img|
67
+
68
+ w = SiteProp.first.page_content_width/3
69
+ h = calc_height_of_image(w)
70
+
71
+ img.resize "#{w}x#{h}>"
72
+ img = yield(img) if block_given?
73
+ img
74
+
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def calc_height_of_image(w)
81
+ model_image = ::MiniMagick::Image.open(model.image.current_path)
82
+ calc_height(w, model_image["width"], model_image["height"])
83
+ end
84
+
85
+ # подгоняем по ширине, рассчитываем высоту
86
+ def calc_height(width, original_w, original_h)
87
+ k = width.to_f/original_w
88
+ original_h * k
89
+ end
90
+
91
+
92
+ end
93
+ end
@@ -0,0 +1,61 @@
1
+ module C80NewsTz
2
+ class GphotoUploader < CarrierWave::Uploader::Base
3
+
4
+ include CarrierWave::MiniMagick
5
+
6
+ storage :file
7
+
8
+ def store_dir
9
+ "uploads/gallery/#{format("%03d", model.gallery_id)}"
10
+ end
11
+
12
+ # ограничение оригинальной картинки
13
+ process :resize_to_limit => [1024, 1024]
14
+
15
+ version :thumb_841 do
16
+ process :resize_to_limit => [841, 672]
17
+ end
18
+
19
+ version :thumb_841fill do
20
+ process :resize_to_fill => [841, 672]
21
+ end
22
+
23
+ version :thumb_841fit do
24
+ process :resize_to_fit => [841, 672]
25
+ end
26
+
27
+ version :thumb_222fill do
28
+ process :resize_to_fill => [222, 176]
29
+ end
30
+
31
+ version :thumb_222fit do
32
+ process :resize_to_fit => [222, 176]
33
+ end
34
+
35
+ version :thumb_186fill do
36
+ process :resize_to_fill => [186, 133]
37
+
38
+ end
39
+
40
+ version :thumb_99 do
41
+ process :resize_to_fill => [99, 78]
42
+ end
43
+
44
+ def filename
45
+ if original_filename
46
+ "photo_#{secure_token(4)}.#{file.extension}"
47
+ end
48
+ end
49
+
50
+ protected
51
+ def secure_token(length=16)
52
+ var = :"@#{mounted_as}_secure_token"
53
+ model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
54
+ end
55
+
56
+ def extension_white_list
57
+ %w(jpg jpeg gif png)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,88 @@
1
+ module C80NewsTz
2
+ class NphotoUploader < CarrierWave::Uploader::Base
3
+
4
+ include CarrierWave::MiniMagick
5
+
6
+ storage :file
7
+
8
+ # При загрузке картинок генерим два thumb:
9
+ # - thumb_big (resize_to_limit),
10
+ # - thumb_small (resize_to_limit: w = page_content*1/3).
11
+
12
+ version :thumb_big do
13
+ process :resize_to_limit_big
14
+ end
15
+
16
+ version :thumb_small do
17
+ process :resize_to_limit_small
18
+ end
19
+
20
+ version :thumb_preview do
21
+ process :resize_to_fill => [229, 152]
22
+ end
23
+
24
+ def store_dir
25
+ "uploads/notices/#{format("%2d", model.notice_id)}"
26
+ end
27
+
28
+ def extension_white_list
29
+ %w(jpg jpeg gif png)
30
+ end
31
+
32
+ def filename
33
+ if original_filename
34
+ "photo_#{secure_token(4)}.#{file.extension}"
35
+ end
36
+ end
37
+
38
+ protected
39
+ def secure_token(length=16)
40
+ var = :"@#{mounted_as}_secure_token"
41
+ model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
42
+ end
43
+
44
+
45
+ def resize_to_limit_big
46
+ # puts "<PageArtUploader.resize_to_limit_big>"
47
+ manipulate! do |img|
48
+
49
+ w = SiteProp.first.page_content_width
50
+ h = calc_height_of_image(w)
51
+
52
+ img.resize "#{w}x#{h}>"
53
+ img = yield(img) if block_given?
54
+ img
55
+
56
+ end
57
+ end
58
+
59
+ def resize_to_limit_small
60
+ # puts "<PageArtUploader.resize_to_limit_small>"
61
+ manipulate! do |img|
62
+
63
+ w = SiteProp.first.page_content_width/3
64
+ h = calc_height_of_image(w)
65
+
66
+ img.resize "#{w}x#{h}>"
67
+ img = yield(img) if block_given?
68
+ img
69
+
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def calc_height_of_image(w)
76
+ model_image = ::MiniMagick::Image.open(model.image.current_path)
77
+ calc_height(w, model_image["width"], model_image["height"])
78
+ end
79
+
80
+ # подгоняем по ширине, рассчитываем высоту
81
+ def calc_height(width, original_w, original_h)
82
+ k = width.to_f/original_w
83
+ original_h * k
84
+ end
85
+
86
+
87
+ end
88
+ end
@@ -0,0 +1,27 @@
1
+ module C80NewsTz
2
+ class PdfUploader < CarrierWave::Uploader::Base
3
+
4
+ storage :file
5
+
6
+ def extension_white_list
7
+ %w(pdf)
8
+ end
9
+
10
+ def filename
11
+ if original_filename
12
+ "file_#{secure_token(4)}.#{file.extension}"
13
+ end
14
+ end
15
+
16
+ def store_dir
17
+ "uploads/pdfs/#{model.id}"
18
+ end
19
+
20
+ protected
21
+ def secure_token(length=16)
22
+ var = :"@#{mounted_as}_secure_token"
23
+ model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ var $cc = $(".ajax_div");
2
+ var html_str = "<%= j render_news_block(true,params[:page]) %>";
3
+
4
+ $cc.html(html_str);
5
+ Holder.run(".ajax_div img");
6
+ fLazyStart();
7
+
8
+ fNewsProccessPaginateLinks();
9
+ fNewsProcessBlocks();
10
+ $('.div_facts').wookmark({ align:"left", offset:20 });
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>News</title>
5
+ <%= stylesheet_link_tag "news/application", media: "all" %>
6
+ <%= javascript_include_tag "news/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <div class="fact" data-url="<%= url_for_fact(fact) %>">
2
+ <p class="date">
3
+ <%= local_time(fact[:created_at], format: '%e.%m.%Y') %>
4
+ </p>
5
+ <%= link_to(url_for_fact(fact)) do %>
6
+ <h5><%= fact.title %></h5>
7
+ <% end %>
8
+ [[1]]
9
+ <p class="short">
10
+ <%= fact[:short].html_safe %>
11
+ </p>
12
+ <div class="white_shadow"></div>
13
+ </div>
@@ -0,0 +1,8 @@
1
+ <div class="ajax_div">
2
+ <%= render :partial => "shared/news_list",
3
+ :locals => {
4
+ :news_list => news_list,
5
+ :is_news_page => is_news_page
6
+ }
7
+ %>
8
+ </div>
@@ -0,0 +1,12 @@
1
+ <div class="div_facts">
2
+ <% news_list.each do |fact| %>
3
+
4
+ <%= check_preview(render_one_fact(fact).to_s, fact.fphotos, fact.title) %>
5
+
6
+ <% end %>
7
+ </div>
8
+ <% if is_news_page %>
9
+ <div class="div_will_paginate">
10
+ <%= will_paginate news_list %>
11
+ </div>
12
+ <% end %>