krant 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +16 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +192 -0
- data/Rakefile +4 -0
- data/admin/krant/broadcast_messages.rb +56 -0
- data/app/assets/stylesheets/krant/active_admin.scss +2 -0
- data/app/assets/stylesheets/krant/active_admin/broadcast_messages.scss +31 -0
- data/app/assets/stylesheets/krant/active_admin/news_list.scss +19 -0
- data/app/models/krant/broadcast_message.rb +10 -0
- data/app/models/krant/broadcast_message_translation.rb +6 -0
- data/app/models/krant/last_seen_state.rb +6 -0
- data/app/models/krant/news_item.rb +35 -0
- data/app/models/krant/translated_broadcast_message.rb +47 -0
- data/bin/console +14 -0
- data/bin/rails +12 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/config/locales/de.yml +23 -0
- data/config/locales/en.yml +23 -0
- data/db/migrate/20171214095614_create_krant_broadcast_messages.rb +9 -0
- data/db/migrate/20171214095622_create_krant_broadcast_message_translations.rb +12 -0
- data/db/migrate/20171214175840_create_krant_news_items.rb +10 -0
- data/db/migrate/20171215080737_create_krant_last_seen_states.rb +10 -0
- data/gemfiles/rails_4.2_active_admin_1.0.0.pre4.gemfile +8 -0
- data/gemfiles/rails_4.2_active_admin_1.0.gemfile +8 -0
- data/gemfiles/rails_4.2_active_admin_1.1.gemfile +8 -0
- data/krant.gemspec +38 -0
- data/lib/krant.rb +57 -0
- data/lib/krant/engine.rb +14 -0
- data/lib/krant/news.rb +102 -0
- data/lib/krant/tasks.rb +26 -0
- data/lib/krant/version.rb +3 -0
- data/lib/krant/views/header_with_broadcast_messages.rb +20 -0
- data/lib/krant/views/news_list.rb +36 -0
- metadata +281 -0
data/lib/krant/engine.rb
ADDED
data/lib/krant/news.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
module Krant
|
2
|
+
# A collection of news items
|
3
|
+
class News
|
4
|
+
# Create a news collection for the given scope.
|
5
|
+
#
|
6
|
+
# @param scope [Module|Class|String] Used to prevent naming
|
7
|
+
# clashes between different news collections, when news item are
|
8
|
+
# persited to the database.
|
9
|
+
def self.about(scope)
|
10
|
+
new(scope: scope.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @api private
|
14
|
+
def initialize(scope:)
|
15
|
+
@templates = {}
|
16
|
+
@scope = scope
|
17
|
+
end
|
18
|
+
|
19
|
+
# @api private
|
20
|
+
attr_reader :scope
|
21
|
+
|
22
|
+
# Define a new item that will be stored in the database on next
|
23
|
+
# `persist` call. Usually called from an initializer, either in
|
24
|
+
# the main application or a plugin gem.
|
25
|
+
#
|
26
|
+
# @param name [String] Unique name for the item. It is good
|
27
|
+
# practice to use the name of the library or plugin as a prefix
|
28
|
+
# and separate different parts of the name with dots. Especially
|
29
|
+
# when multiple plugin gems define news for a common scope, this
|
30
|
+
# prevents naming clashes.
|
31
|
+
#
|
32
|
+
# @param [Hash] options
|
33
|
+
#
|
34
|
+
# @option options [Hash] :title A hash with locales as keys and
|
35
|
+
# short titles that can displayed in a header as values.
|
36
|
+
#
|
37
|
+
# @option options [Hash] :text A hash with locales as keys and
|
38
|
+
# longer descriptions of the new feature as values. Use Markdown
|
39
|
+
# to format the text.
|
40
|
+
#
|
41
|
+
# @example Add a news item
|
42
|
+
# MyApp.news.item('some_plugin.social_share_links',
|
43
|
+
# title: {
|
44
|
+
# en: 'Social Share Links',
|
45
|
+
# de: 'Teilen Links'
|
46
|
+
# },
|
47
|
+
# text: {
|
48
|
+
# en: 'Now displays links to [Twitter](http://twitter.com).'
|
49
|
+
# en: 'Zeigt nun Links zu [Twitter](http://twitter.com).'
|
50
|
+
# })
|
51
|
+
#
|
52
|
+
def item(name, attributes)
|
53
|
+
@templates[name.to_s] = attributes
|
54
|
+
end
|
55
|
+
|
56
|
+
# @api private
|
57
|
+
def persist
|
58
|
+
@templates.each do |name, template|
|
59
|
+
NewsItem.find_or_create_by(scope: @scope, name: name) do |news_item|
|
60
|
+
if block_given?
|
61
|
+
news_item.template = template
|
62
|
+
yield news_item
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @api private
|
69
|
+
def all(for_user:)
|
70
|
+
last_seen_at = last_seen(for_user)
|
71
|
+
|
72
|
+
persisted_items.order('created_at desc').select do |news_item|
|
73
|
+
news_item.seen = last_seen_at && news_item.created_at <= last_seen_at
|
74
|
+
news_item.template = @templates[news_item.name]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# @api private
|
79
|
+
def unseen_items?(for_user:)
|
80
|
+
last_seen_at = last_seen(for_user)
|
81
|
+
|
82
|
+
scope = persisted_items
|
83
|
+
scope = scope.where('created_at > ?', last_seen_at) if last_seen_at
|
84
|
+
scope.exists?
|
85
|
+
end
|
86
|
+
|
87
|
+
# @api private
|
88
|
+
def seen_by!(user)
|
89
|
+
LastSeenState.find_or_create_by(scope: @scope, user: user).touch
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def persisted_items
|
95
|
+
NewsItem.where(scope: @scope)
|
96
|
+
end
|
97
|
+
|
98
|
+
def last_seen(user)
|
99
|
+
LastSeenState.where(scope: @scope, user: user).first.try(:updated_at)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/krant/tasks.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
module Krant
|
4
|
+
# Create database records for each new news item. Together with
|
5
|
+
# the "last seen" timestamp of a user, the corresponding creation
|
6
|
+
# timestamps will be used to determine seen/unseen state of each
|
7
|
+
# news item.
|
8
|
+
module Tasks
|
9
|
+
extend Rake::DSL
|
10
|
+
|
11
|
+
# Defines a news:persist task that persists news items to the
|
12
|
+
# database.
|
13
|
+
#
|
14
|
+
# @param news [Krant::News] Collection to read items from.
|
15
|
+
def self.install(&block)
|
16
|
+
desc 'Persist news items'
|
17
|
+
task 'news:persist' => 'environment' do
|
18
|
+
news = block.call
|
19
|
+
puts "Persisting news for #{news.scope}..."
|
20
|
+
news.persist do |news_item|
|
21
|
+
puts "- #{news_item.name}: #{news_item.title}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Krant
|
2
|
+
module Views
|
3
|
+
# Extends the normal Active Admin header to include broadcast
|
4
|
+
# messages.
|
5
|
+
class HeaderWithBroadcastMessages < Arbre::Component
|
6
|
+
builder_method :krant_header_with_broadcast_messages
|
7
|
+
|
8
|
+
def build(*args)
|
9
|
+
insert_tag(ActiveAdmin::Views::Header, *args)
|
10
|
+
div do
|
11
|
+
TranslatedBroadcastMessage.active.each do |broadcast_message|
|
12
|
+
div class: 'krant-broadcast-messages-bar' do
|
13
|
+
broadcast_message.text
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Krant
|
2
|
+
module Views
|
3
|
+
# A list of recent news. Rendering the component marks news as
|
4
|
+
# seen.
|
5
|
+
class NewsList < Arbre::Component
|
6
|
+
builder_method :krant_news_list
|
7
|
+
|
8
|
+
# @param news [Krant::News] News collection to take news from.
|
9
|
+
def build(news)
|
10
|
+
super(class: 'krant-news-list')
|
11
|
+
|
12
|
+
news.all(for_user: current_active_admin_user).each do |news_item|
|
13
|
+
item(news_item)
|
14
|
+
end
|
15
|
+
|
16
|
+
script raw('jQuery.post(location.pathname + "/seen")')
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def item(news_item)
|
22
|
+
div class: item_css_class(news_item) do
|
23
|
+
h3 news_item.title
|
24
|
+
text_node Kramdown::Document.new(news_item.text).to_html.html_safe
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def item_css_class(news_item)
|
29
|
+
[
|
30
|
+
'krant-news-list-item',
|
31
|
+
news_item.seen? ? 'krant-news-list-item-seen' : 'krant-news-list-item-unseen'
|
32
|
+
].compact.join(' ')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: krant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Fischbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: appraisal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: combustion
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.7.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.7.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: capybara
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.15'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.15'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: factory_bot_rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: domino
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.7.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.7.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: semmy
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '1.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: timecop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.7.1
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.7.1
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: activeadmin
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.x
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.x
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rails
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '4.2'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '4.2'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: kramdown
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '1.5'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '1.5'
|
209
|
+
description:
|
210
|
+
email:
|
211
|
+
- tfischbach@codevise.de
|
212
|
+
executables: []
|
213
|
+
extensions: []
|
214
|
+
extra_rdoc_files: []
|
215
|
+
files:
|
216
|
+
- ".gitignore"
|
217
|
+
- ".rspec"
|
218
|
+
- ".rubocop.yml"
|
219
|
+
- ".travis.yml"
|
220
|
+
- Appraisals
|
221
|
+
- CHANGELOG.md
|
222
|
+
- CODE_OF_CONDUCT.md
|
223
|
+
- Gemfile
|
224
|
+
- LICENSE.txt
|
225
|
+
- README.md
|
226
|
+
- Rakefile
|
227
|
+
- admin/krant/broadcast_messages.rb
|
228
|
+
- app/assets/stylesheets/krant/active_admin.scss
|
229
|
+
- app/assets/stylesheets/krant/active_admin/broadcast_messages.scss
|
230
|
+
- app/assets/stylesheets/krant/active_admin/news_list.scss
|
231
|
+
- app/models/krant/broadcast_message.rb
|
232
|
+
- app/models/krant/broadcast_message_translation.rb
|
233
|
+
- app/models/krant/last_seen_state.rb
|
234
|
+
- app/models/krant/news_item.rb
|
235
|
+
- app/models/krant/translated_broadcast_message.rb
|
236
|
+
- bin/console
|
237
|
+
- bin/rails
|
238
|
+
- bin/rspec
|
239
|
+
- bin/setup
|
240
|
+
- config/locales/de.yml
|
241
|
+
- config/locales/en.yml
|
242
|
+
- db/migrate/20171214095614_create_krant_broadcast_messages.rb
|
243
|
+
- db/migrate/20171214095622_create_krant_broadcast_message_translations.rb
|
244
|
+
- db/migrate/20171214175840_create_krant_news_items.rb
|
245
|
+
- db/migrate/20171215080737_create_krant_last_seen_states.rb
|
246
|
+
- gemfiles/rails_4.2_active_admin_1.0.0.pre4.gemfile
|
247
|
+
- gemfiles/rails_4.2_active_admin_1.0.gemfile
|
248
|
+
- gemfiles/rails_4.2_active_admin_1.1.gemfile
|
249
|
+
- krant.gemspec
|
250
|
+
- lib/krant.rb
|
251
|
+
- lib/krant/engine.rb
|
252
|
+
- lib/krant/news.rb
|
253
|
+
- lib/krant/tasks.rb
|
254
|
+
- lib/krant/version.rb
|
255
|
+
- lib/krant/views/header_with_broadcast_messages.rb
|
256
|
+
- lib/krant/views/news_list.rb
|
257
|
+
homepage: https://github.com/codevise/krant
|
258
|
+
licenses:
|
259
|
+
- MIT
|
260
|
+
metadata: {}
|
261
|
+
post_install_message:
|
262
|
+
rdoc_options: []
|
263
|
+
require_paths:
|
264
|
+
- lib
|
265
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
266
|
+
requirements:
|
267
|
+
- - "~>"
|
268
|
+
- !ruby/object:Gem::Version
|
269
|
+
version: '2.1'
|
270
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
271
|
+
requirements:
|
272
|
+
- - ">="
|
273
|
+
- !ruby/object:Gem::Version
|
274
|
+
version: '0'
|
275
|
+
requirements: []
|
276
|
+
rubyforge_project:
|
277
|
+
rubygems_version: 2.7.0
|
278
|
+
signing_key:
|
279
|
+
specification_version: 4
|
280
|
+
summary: Display app news and broadcast messages in Active Admin.
|
281
|
+
test_files: []
|