c80_news 0.1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +1 -0
- data/app/admin/c80_news/facts.rb +66 -0
- data/app/assets/images/c80_news/.keep +0 -0
- data/app/assets/javascripts/c80_news/application.js.coffee +1 -0
- data/app/assets/javascripts/c80_news/facts_ajax.js +68 -0
- data/app/assets/javascripts/c80_news/facts_wookmark.js +10 -0
- data/app/assets/stylesheets/c80_news/application.scss +5 -0
- data/app/assets/stylesheets/c80_news/facts_wookmark.scss +27 -0
- data/app/controllers/c80_news/application_controller.rb +10 -0
- data/app/helpers/c80_news/application_helper.rb +37 -0
- data/app/models/c80_news/fact.rb +40 -0
- data/app/models/c80_news/fact_validator.rb +19 -0
- data/app/models/c80_news/fphoto.rb +44 -0
- data/app/models/c80_news/prop.rb +5 -0
- data/app/uploaders/c80_news/fphoto_uploader.rb +93 -0
- data/app/views/c80_news/application/guru.js.erb +10 -0
- data/app/views/layouts/c80_news/application.html.erb +14 -0
- data/app/views/shared/_fact.html.erb +13 -0
- data/app/views/shared/_news_block.html.erb +8 -0
- data/app/views/shared/_news_list.html.erb +12 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/c80_news.gemspec +27 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20151213202020_create_news_fact.rb +15 -0
- data/db/migrate/20151213203030_create_news_fphotos.rb +11 -0
- data/db/migrate/20151214133030_create_news_props.rb +9 -0
- data/lib/c80_news/engine.rb +23 -0
- data/lib/c80_news/version.rb +3 -0
- data/lib/c80_news.rb +5 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a67609fa49d757d4a3a5842cce8439bd8084b9dc
|
4
|
+
data.tar.gz: d8378d89a61898d3048e73377f6bde1f32e8cb13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdfe0af420296e748237247622317903f8368f113ea66b15437fbafb903aa8a5863d7f20ad6a1957d21ca5b3b3b81eddc49cc38973dfc980bcff3aaa05359974
|
7
|
+
data.tar.gz: e7269b232af5224c39327818c5057569438771a7847ca2f126eecd342db48f445a5c05da7a30ec14e078ac2e888b0c88e08390519bbff7566ba9f4290514f785
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 C80609A
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# C80News
|
2
|
+
|
3
|
+
This gem adds news to site.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'c80_news'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install c80_news
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1) `rake db:migrate`
|
24
|
+
2) `vi db/seed/07_fill_news_props.rb`:
|
25
|
+
|
26
|
+
```
|
27
|
+
# rake db:seed:07_fill_news_props
|
28
|
+
|
29
|
+
C80News::Prop.delete_all
|
30
|
+
C80News::Prop.create!({ per_page:8, per_widget:4 })
|
31
|
+
```
|
32
|
+
3) `rake db:seed:07_fill_news_props`
|
33
|
+
4. Add the line to application's routes file:
|
34
|
+
```
|
35
|
+
mount C80News::Engine => '/'
|
36
|
+
```
|
37
|
+
5) Add this line to `application.js.coffee`:
|
38
|
+
```
|
39
|
+
#= require c80_news
|
40
|
+
```
|
41
|
+
6) Add this line to `application.scss`:
|
42
|
+
```
|
43
|
+
@import "c80_news/application";
|
44
|
+
```
|
45
|
+
7) Add this line to `application_controller.rb`:
|
46
|
+
```
|
47
|
+
helper C80News::Engine.helpers
|
48
|
+
```
|
49
|
+
|
50
|
+
## Available helper methods
|
51
|
+
|
52
|
+
```
|
53
|
+
render_news_block
|
54
|
+
render_one_fact
|
55
|
+
```
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it ( https://github.com/[my-github-username]/c80_news/fork )
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
ActiveAdmin.register C80News::Fact, :as => 'Fact' do
|
2
|
+
|
3
|
+
before_filter :skip_sidebar!, :only => :index
|
4
|
+
|
5
|
+
menu :label => 'Новости'
|
6
|
+
|
7
|
+
permit_params :short,
|
8
|
+
:title,
|
9
|
+
:full,
|
10
|
+
# :keywords,
|
11
|
+
# :description,
|
12
|
+
:fphotos_attributes => [:id,:image,:_destroy]
|
13
|
+
|
14
|
+
# controller do
|
15
|
+
# cache_sweeper :suit_sweeper, :only => [:update,:create,:destroy]
|
16
|
+
# end
|
17
|
+
|
18
|
+
index do
|
19
|
+
selectable_column
|
20
|
+
id_column
|
21
|
+
column :title
|
22
|
+
column :created_at do |fact|
|
23
|
+
local_time(fact[:created_at], format: '%e.%m.%Y')
|
24
|
+
end
|
25
|
+
|
26
|
+
column '' do |fact|
|
27
|
+
if fact.fphotos.count > 0
|
28
|
+
image_tag(fact.fphotos.first.image.thumb_preview)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
column :short
|
33
|
+
column :full
|
34
|
+
|
35
|
+
actions
|
36
|
+
end
|
37
|
+
|
38
|
+
form(:html => {:multipart => true}) do |f|
|
39
|
+
f.inputs 'Свойства' do
|
40
|
+
f.input :title
|
41
|
+
|
42
|
+
f.inputs 'Фото' do
|
43
|
+
f.has_many :fphotos, :allow_destroy => true do |fphoto|
|
44
|
+
fphoto.input :image,
|
45
|
+
:as => :file,
|
46
|
+
:hint => image_tag(fphoto.object.image.thumb_preview)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
f.input :short
|
51
|
+
f.input :full, :as => :ckeditor
|
52
|
+
|
53
|
+
|
54
|
+
# f.input :keywords,
|
55
|
+
# :input_html => {
|
56
|
+
# :class => 'code_area',
|
57
|
+
# :rows => 2
|
58
|
+
# }#,
|
59
|
+
# :hint => "[SEO] meta Keywords; Поле можно оставить пустым, тогда будут использованы ключевые слова сайта:<br> #{SiteProps.first.keywords}".html_safe
|
60
|
+
#f.input :description, :hint => "[SEO] meta Description; Поле можно оставить пустым, тогда будут использованы 200 первых символов новости."
|
61
|
+
|
62
|
+
end
|
63
|
+
f.actions
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
#= require_tree .
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
// Код, реализующий ajax функционал на странице "новости"
|
4
|
+
|
5
|
+
var fNewsBindHistoryAdapter;
|
6
|
+
var fNewsdoAjaxRequest;
|
7
|
+
var fNewsProccessPaginateLinks;
|
8
|
+
var fNewsStartWillPaginateAjax;
|
9
|
+
var fNewsProcessBlocks; // при клике по preview-картинке новости будет происходить переход на просмотр новости
|
10
|
+
|
11
|
+
$(function () {
|
12
|
+
if ($("body#news").length == 1) {
|
13
|
+
|
14
|
+
fNewsBindHistoryAdapter = function () {
|
15
|
+
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
|
16
|
+
|
17
|
+
// Log the State
|
18
|
+
var State = History.getState(); // Note: We are using History.getState() instead of event.state
|
19
|
+
var p;
|
20
|
+
|
21
|
+
//History.log('statechange:', State.data, State.title, State.url);
|
22
|
+
if (State.title == "") {
|
23
|
+
p = 1;
|
24
|
+
} else {
|
25
|
+
p = State.data.page;
|
26
|
+
}
|
27
|
+
|
28
|
+
fNewsdoAjaxRequest(p);
|
29
|
+
});
|
30
|
+
};
|
31
|
+
|
32
|
+
fNewsdoAjaxRequest = function (page/*integer*/,callback/*function*/) {
|
33
|
+
$.ajax({
|
34
|
+
url: "/news_guru",
|
35
|
+
type: "POST",
|
36
|
+
data: {page: page},
|
37
|
+
dataType: "script"
|
38
|
+
}).done(callback);
|
39
|
+
};
|
40
|
+
|
41
|
+
fNewsProccessPaginateLinks = function () {
|
42
|
+
//console.log("fNewsProccessPaginateLinks");
|
43
|
+
$(".div_will_paginate a").click(function (e) {
|
44
|
+
e.preventDefault();
|
45
|
+
var page = $(this).attr('href').split("?page=")[1];
|
46
|
+
History.pushState({page:page},window.document.title,"?page="+page);
|
47
|
+
});
|
48
|
+
};
|
49
|
+
|
50
|
+
fNewsStartWillPaginateAjax = function () {
|
51
|
+
if ($(".div_will_paginate a").length > 0) {
|
52
|
+
fNewsProccessPaginateLinks();
|
53
|
+
fNewsBindHistoryAdapter();
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
fNewsProcessBlocks = function() {
|
58
|
+
$(".fact img").click(function (e) {
|
59
|
+
// NB:: parent().parent() хардкод: картинка лежит в ссылке, ссылка лежит в диве
|
60
|
+
window.location.href = $(this).parent().parent().data('url');
|
61
|
+
});
|
62
|
+
};
|
63
|
+
|
64
|
+
fNewsStartWillPaginateAjax();
|
65
|
+
fNewsProcessBlocks();
|
66
|
+
|
67
|
+
}
|
68
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/**
|
2
|
+
* Grid container
|
3
|
+
*/
|
4
|
+
.div_facts {
|
5
|
+
position: relative; /** Needed to ensure items are laid out relative to this container **/
|
6
|
+
padding: 0;
|
7
|
+
margin: 0;
|
8
|
+
display: none;
|
9
|
+
|
10
|
+
.fact {
|
11
|
+
display: block;
|
12
|
+
float: left;
|
13
|
+
width: 229px;
|
14
|
+
max-height: 350px;
|
15
|
+
overflow: hidden;
|
16
|
+
margin-bottom: 20px;
|
17
|
+
|
18
|
+
img {
|
19
|
+
margin-bottom: 10px;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
div.news_widget {
|
26
|
+
background-color: #b0b0b0;
|
27
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module C80News
|
3
|
+
module ApplicationHelper
|
4
|
+
|
5
|
+
include LocalTimeHelper
|
6
|
+
|
7
|
+
def render_news_block(is_news_page=false,page=1)
|
8
|
+
|
9
|
+
|
10
|
+
if is_news_page
|
11
|
+
per_page = C80News::Prop.first.per_page
|
12
|
+
news = Fact.paginate(:page => page,:per_page => per_page)
|
13
|
+
else
|
14
|
+
per_widget = C80News::Prop.first.per_widget
|
15
|
+
news = Fact.limit(per_widget)
|
16
|
+
end
|
17
|
+
|
18
|
+
render :partial => "shared/news_block",
|
19
|
+
:locals => {
|
20
|
+
:news_list => news,
|
21
|
+
:is_news_page => is_news_page
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_one_fact(fact)
|
26
|
+
render :partial => "shared/fact",
|
27
|
+
:locals => {
|
28
|
+
fact: fact
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def url_for_fact(fact)
|
33
|
+
"news/#{fact.slug}"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "babosa"
|
2
|
+
include ActionView::Helpers::SanitizeHelper
|
3
|
+
|
4
|
+
module C80News
|
5
|
+
class Fact < ActiveRecord::Base
|
6
|
+
has_many :fphotos, :dependent => :destroy
|
7
|
+
accepts_nested_attributes_for :fphotos,
|
8
|
+
:reject_if => lambda { |attributes|
|
9
|
+
!attributes.present?
|
10
|
+
},
|
11
|
+
:allow_destroy => true
|
12
|
+
|
13
|
+
validates_with FactValidator
|
14
|
+
default_scope {order(:created_at => :desc)}
|
15
|
+
|
16
|
+
extend FriendlyId
|
17
|
+
friendly_id :title, use: :slugged
|
18
|
+
def normalize_friendly_id(input)
|
19
|
+
input.to_s.to_slug.normalize(transliterations: :russian).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def slug_candidates
|
23
|
+
[:title] + Array.new(6) {|index| [:title, index+2]}
|
24
|
+
end
|
25
|
+
|
26
|
+
def short_meta_description
|
27
|
+
|
28
|
+
if description.present? && description.length > 200
|
29
|
+
result = description
|
30
|
+
elsif full.present? && full.length > 0
|
31
|
+
result = strip_tags(full[0..200]+"...")
|
32
|
+
else
|
33
|
+
result = nil
|
34
|
+
end
|
35
|
+
result
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module C80News
|
2
|
+
class FactValidator < ActiveModel::Validator
|
3
|
+
def validate(record)
|
4
|
+
|
5
|
+
unless record.title.present?
|
6
|
+
record.errors[:title] = 'Название новости не может быть пустым'
|
7
|
+
end
|
8
|
+
|
9
|
+
unless record.short.present?
|
10
|
+
record.errors[:short] = 'Заполните краткое описание новости'
|
11
|
+
end
|
12
|
+
|
13
|
+
unless record.full.present?
|
14
|
+
record.errors[:full] = 'Текст новости не может быть пустым'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module C80News
|
2
|
+
class Fphoto < ActiveRecord::Base
|
3
|
+
belongs_to :facts
|
4
|
+
mount_uploader :image, FphotoUploader
|
5
|
+
|
6
|
+
# NOTE:: ~Fphoto,PageArt,BaseArt~
|
7
|
+
# NOTE:: содержит повторяющийся код (content_image,content_image_size)
|
8
|
+
# NOTE:: этот код имеется в PageArt.
|
9
|
+
# NOTE:: Fphoto и PageArt можно унаследовать от нового класса BaseArt,
|
10
|
+
# NOTE:: куда надо перенести методы (content_image,content_image_size)
|
11
|
+
|
12
|
+
# в ~ от размеров thumb-ов и page_content_width - выдать соответствующую картинку
|
13
|
+
# • Если у картинки thumb_big шириной ≥ page_content_width - вставляем этот thumb_big.
|
14
|
+
# • Иначе: вставлем thumb_small.
|
15
|
+
def content_image
|
16
|
+
img = MiniMagick::Image.open(image.thumb_big.path)
|
17
|
+
w = SiteProp.first.page_content_width
|
18
|
+
if img["width"] < w
|
19
|
+
image.thumb_small
|
20
|
+
else
|
21
|
+
image.thumb_big
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# выдать размеры картинки, которая будет вставлена в текст страницы
|
26
|
+
def content_image_size
|
27
|
+
img = MiniMagick::Image.open(image.thumb_big.path)
|
28
|
+
w = SiteProp.first.page_content_width
|
29
|
+
if img["width"] < w
|
30
|
+
img = MiniMagick::Image.open(image.thumb_small.path)
|
31
|
+
[img["width"],img["height"]]
|
32
|
+
else
|
33
|
+
[img["width"],img["height"]]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# выдать размеры картинки thumb_preview
|
38
|
+
def thumb_preview_size
|
39
|
+
img = MiniMagick::Image.open(image.thumb_preview.path)
|
40
|
+
[img["width"],img["height"]]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module C80News
|
2
|
+
class FphotoUploader < BaseFileUploader
|
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,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,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 %>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "c80_news"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/c80_news.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'c80_news/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "c80_news"
|
8
|
+
spec.version = C80News::VERSION
|
9
|
+
spec.authors = ["C80609A"]
|
10
|
+
spec.email = ["c080609a@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "News gem"
|
13
|
+
spec.description = "Gem adds news to site"
|
14
|
+
spec.homepage = "https://github.com/c080609a/c80_news"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_dependency 'activesupport', ['>= 3.0.0']
|
25
|
+
spec.add_dependency "rails", "~> 4.2.0"
|
26
|
+
spec.add_dependency "local_time"
|
27
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateNewsFact < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :c80_news_facts, :options => 'COLLATE=utf8_unicode_ci' do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :sub_title
|
6
|
+
t.text :short
|
7
|
+
t.text :full
|
8
|
+
t.string :keywords
|
9
|
+
t.string :description
|
10
|
+
t.string :slug
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module C80News
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace C80News
|
4
|
+
|
5
|
+
initializer :c80_news_engine do
|
6
|
+
if defined?(ActiveAdmin)
|
7
|
+
ActiveAdmin.application.load_paths += Dir["#{config.root}/app/models/**/"]
|
8
|
+
#ActiveAdmin.application.load_paths += Dir["#{config.root}/app/models/concerns/**/"]
|
9
|
+
ActiveAdmin.application.load_paths += Dir["#{config.root}/app/admin/c80_news/**/"]
|
10
|
+
# ActiveAdmin.application.load_paths += Dir["#{config.root}/app/jobs/**/"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer :append_migrations do |app|
|
15
|
+
unless app.root.to_s.match root.to_s
|
16
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
17
|
+
app.config.paths["db/migrate"] << expanded_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/c80_news.rb
ADDED
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: c80_news
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- C80609A
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: local_time
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Gem adds news to site
|
84
|
+
email:
|
85
|
+
- c080609a@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- app/admin/c80_news/facts.rb
|
98
|
+
- app/assets/images/c80_news/.keep
|
99
|
+
- app/assets/javascripts/c80_news/application.js.coffee
|
100
|
+
- app/assets/javascripts/c80_news/facts_ajax.js
|
101
|
+
- app/assets/javascripts/c80_news/facts_wookmark.js
|
102
|
+
- app/assets/stylesheets/c80_news/application.scss
|
103
|
+
- app/assets/stylesheets/c80_news/facts_wookmark.scss
|
104
|
+
- app/controllers/c80_news/application_controller.rb
|
105
|
+
- app/helpers/c80_news/application_helper.rb
|
106
|
+
- app/models/c80_news/fact.rb
|
107
|
+
- app/models/c80_news/fact_validator.rb
|
108
|
+
- app/models/c80_news/fphoto.rb
|
109
|
+
- app/models/c80_news/prop.rb
|
110
|
+
- app/uploaders/c80_news/fphoto_uploader.rb
|
111
|
+
- app/views/c80_news/application/guru.js.erb
|
112
|
+
- app/views/layouts/c80_news/application.html.erb
|
113
|
+
- app/views/shared/_fact.html.erb
|
114
|
+
- app/views/shared/_news_block.html.erb
|
115
|
+
- app/views/shared/_news_list.html.erb
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- c80_news.gemspec
|
119
|
+
- config/routes.rb
|
120
|
+
- db/migrate/20151213202020_create_news_fact.rb
|
121
|
+
- db/migrate/20151213203030_create_news_fphotos.rb
|
122
|
+
- db/migrate/20151214133030_create_news_props.rb
|
123
|
+
- lib/c80_news.rb
|
124
|
+
- lib/c80_news/engine.rb
|
125
|
+
- lib/c80_news/version.rb
|
126
|
+
homepage: https://github.com/c080609a/c80_news
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.5.1
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: News gem
|
150
|
+
test_files: []
|