krant 0.1.0

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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +14 -0
  5. data/.travis.yml +16 -0
  6. data/Appraisals +14 -0
  7. data/CHANGELOG.md +7 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +192 -0
  12. data/Rakefile +4 -0
  13. data/admin/krant/broadcast_messages.rb +56 -0
  14. data/app/assets/stylesheets/krant/active_admin.scss +2 -0
  15. data/app/assets/stylesheets/krant/active_admin/broadcast_messages.scss +31 -0
  16. data/app/assets/stylesheets/krant/active_admin/news_list.scss +19 -0
  17. data/app/models/krant/broadcast_message.rb +10 -0
  18. data/app/models/krant/broadcast_message_translation.rb +6 -0
  19. data/app/models/krant/last_seen_state.rb +6 -0
  20. data/app/models/krant/news_item.rb +35 -0
  21. data/app/models/krant/translated_broadcast_message.rb +47 -0
  22. data/bin/console +14 -0
  23. data/bin/rails +12 -0
  24. data/bin/rspec +17 -0
  25. data/bin/setup +8 -0
  26. data/config/locales/de.yml +23 -0
  27. data/config/locales/en.yml +23 -0
  28. data/db/migrate/20171214095614_create_krant_broadcast_messages.rb +9 -0
  29. data/db/migrate/20171214095622_create_krant_broadcast_message_translations.rb +12 -0
  30. data/db/migrate/20171214175840_create_krant_news_items.rb +10 -0
  31. data/db/migrate/20171215080737_create_krant_last_seen_states.rb +10 -0
  32. data/gemfiles/rails_4.2_active_admin_1.0.0.pre4.gemfile +8 -0
  33. data/gemfiles/rails_4.2_active_admin_1.0.gemfile +8 -0
  34. data/gemfiles/rails_4.2_active_admin_1.1.gemfile +8 -0
  35. data/krant.gemspec +38 -0
  36. data/lib/krant.rb +57 -0
  37. data/lib/krant/engine.rb +14 -0
  38. data/lib/krant/news.rb +102 -0
  39. data/lib/krant/tasks.rb +26 -0
  40. data/lib/krant/version.rb +3 -0
  41. data/lib/krant/views/header_with_broadcast_messages.rb +20 -0
  42. data/lib/krant/views/news_list.rb +36 -0
  43. metadata +281 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 16fca9a5203f41e933e1708ca649373a256c10e4d2f0ac45759a4555a956a408
4
+ data.tar.gz: 935126c44cc0a3fd0c5de5a360016ae66e20b0faa41733ebe04c639d2775c41b
5
+ SHA512:
6
+ metadata.gz: ede4f46671bf12e023594dc0822db6c3e653d38481d76bc943f0df97e991d924cb5ef78f4930828e1c5501a1f4311464effb394168677f42e2609b85a048446d
7
+ data.tar.gz: 1e668b5be312e32b4be57f54a1fe5ed301761a66852086dd51b1a56d907b2ac9104a33d20f1fa70441abe836f4c94c5de7c59b2b2c247b0ef6e70c489ac2b425
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /gemfiles/*.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /spec/internal/tmp
12
+ /spec/internal/db/*.sqlite
13
+ /spec/examples.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ # The default of 80 characters is a little to narrow.
5
+ Metrics/LineLength:
6
+ Max: 100
7
+
8
+ # Do not warn about missing magic comment
9
+ Style/FrozenStringLiteralComment:
10
+ Enabled: false
11
+
12
+ # Allow using {} when chaining methods
13
+ Style/BlockDelimiters:
14
+ EnforcedStyle: braces_for_chaining
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.4
4
+
5
+ # Use container based travis infrastructure which allows caching
6
+ # features for open source projects.
7
+ sudo: false
8
+ cache:
9
+ bundler: true
10
+
11
+ gemfile:
12
+ - gemfiles/rails_4.2_active_admin_1.0.0.pre4.gemfile
13
+ - gemfiles/rails_4.2_active_admin_1.0.gemfile
14
+ - gemfiles/rails_4.2_active_admin_1.1.gemfile
15
+
16
+ script: bundle exec rspec
data/Appraisals ADDED
@@ -0,0 +1,14 @@
1
+ appraise 'rails-4.2-active-admin-1.0.0.pre4' do
2
+ gem 'rails', '~> 4.2'
3
+ gem 'activeadmin', '1.0.0.pre4'
4
+ end
5
+
6
+ appraise 'rails-4.2-active-admin-1.0' do
7
+ gem 'rails', '~> 4.2'
8
+ gem 'activeadmin', '~> 1.0'
9
+ end
10
+
11
+ appraise 'rails-4.2-active-admin-1.1' do
12
+ gem 'rails', '~> 4.2'
13
+ gem 'activeadmin', '~> 1.1'
14
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ### Version 0.1.0
4
+
5
+ 2017-12-15
6
+
7
+ - Initial release.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tfischbach@codevise.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in krant.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Tim Fischbach
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,192 @@
1
+ # Krant
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/krant.svg)](http://badge.fury.io/rb/krant)
4
+ [![Build Status](https://travis-ci.org/codevise/krant.svg?branch=master)](https://travis-ci.org/codevise/krant)
5
+
6
+ Display app news and broadcast messages in Active Admin.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'krant'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ $ bundle
20
+ ```
21
+
22
+ Include javascripts and stylesheets:
23
+
24
+ ```scss
25
+ // app/assets/stylesheets/active_admin.scss
26
+
27
+ // After active_admin/base has been imported
28
+ @import "krant/active_admin";
29
+ ```
30
+
31
+ Install migrations and migrate:
32
+
33
+ ```
34
+ $ bin/rake krant:install:migrations
35
+ $ bin/rake db:migrate
36
+ ```
37
+
38
+ ### Display Broadcast Messages
39
+
40
+ Configure the Active Admin view component and add the broadcast
41
+ messages admin to the load path:
42
+
43
+ ```ruby
44
+ # config/initializers/active_admin.rb
45
+ ActiveAdmin.application.load_paths.unshift(Krant.active_admin_load_path)
46
+
47
+ ActiveAdmin.setup do |config|
48
+ config.view_factory.header = Krant::Views::HeaderWithBroadcastMessages
49
+ end
50
+ ```
51
+
52
+ Configure for which locales you want to enter broadcast message
53
+ translations. The corresponding text fields will be displayed:
54
+
55
+ ```ruby
56
+ # config/initializers/krant.rb
57
+ Krant.broadcast_message_locales = [:en, :fr, :es]
58
+ ```
59
+
60
+ Messages with different translations can now be configured via the
61
+ admin interface and will be displayed once marked as active.
62
+
63
+ The color of the broadcast message bar can be configured via SCSS
64
+
65
+ ```scss
66
+ // app/assets/stylesheets/active_admin.scss
67
+
68
+ $krant-broadcast-message-bar-color: #fff3bd;
69
+ $krant-broadcast-message-bar-border-color: transparent;
70
+
71
+ @import "krant/active_admin";
72
+ ```
73
+
74
+ ### Displaying a News Page
75
+
76
+ Provide a news collection:
77
+
78
+ ```ruby
79
+ # lib/my_app.rb
80
+ module MyApp
81
+ def self.news
82
+ @news ||= Krant::News.about(MyApp)
83
+ end
84
+ end
85
+ ```
86
+
87
+ The passed parameter is only used as a namespace for item names. You
88
+ can also pass a string. Passing a constant is an easy way to ensure
89
+ uniqness.
90
+
91
+ Add a news page:
92
+
93
+ ```ruby
94
+ # app/admins/news.rb
95
+ ActiveAdmin.register_page 'news' do
96
+ Krant.active_admin_news_page(self)
97
+
98
+ content title: 'News' do
99
+ krant_news_list(MyApp.news)
100
+ end
101
+ end
102
+ ```
103
+
104
+ If you are using the CanCan authorization adapter, grant access to the
105
+ page and its `seen` action:
106
+
107
+ ```ruby
108
+ # app/models/ability.rb
109
+ can [:read, :seen], ActiveAdmin::Page, name: 'news'
110
+ ```
111
+
112
+ Add a link to the news page into the utility navigation:
113
+
114
+ ```ruby
115
+ # config/initializers/active_admin.rb
116
+ config.namespace :admin do |admin|
117
+ admin.build_menu :utility_navigation do |menu|
118
+ Krant.add_active_admin_news_menu_item_to(menu,
119
+ news: MyApp.news,
120
+ url: -> { admin_news_path })
121
+ end
122
+ end
123
+ ```
124
+ Create news items for new features:
125
+
126
+ ```ruby
127
+ # config/initializers/news/some_new_feature.rb
128
+ MyApp.news.item(:some_new_feature,
129
+ title: {
130
+ en: 'Some title',
131
+ de: 'Ein Titel'
132
+ },
133
+ body: {
134
+ en: 'Some text using [Markdown](http://http://commonmark.org/).',
135
+ de: 'Text mit [Markdown](http://http://commonmark.org/).',
136
+ })
137
+ ```
138
+
139
+ Define a Rake tasks to persists news items in the database:
140
+
141
+ ```ruby
142
+ # Rakefile
143
+ require 'krant/tasks'
144
+ Krant::Trasks.install { MyApp.news }
145
+ ```
146
+
147
+ and run the defined task after each deploy:
148
+
149
+ ```
150
+ $ bin/rake news:persist
151
+ ```
152
+
153
+ ## Development
154
+
155
+ After checking out the repo, run `bin/setup` to install
156
+ dependencies. You can also run `bin/console` for an interactive prompt
157
+ that will allow you to experiment.
158
+
159
+ To run the tests install bundled gems and invoke RSpec:
160
+
161
+ ```
162
+ $ bundle
163
+ $ bundle exec rspec
164
+ ```
165
+
166
+ The test suite can be run against different versions of Rails and
167
+ Active Admin (see `Appraisals` file):
168
+
169
+ ```
170
+ $ appraisal install
171
+ $ appraisal rspec
172
+ ```
173
+
174
+ To install this gem onto your local machine, run `bundle exec rake
175
+ install`. To release a new version, update the version number in
176
+ `version.rb`, and then run `bundle exec rake release`, which will
177
+ create a git tag for the version, push git commits and tags, and push
178
+ the `.gem` file to [rubygems.org](https://rubygems.org).
179
+
180
+ ## Contributing
181
+
182
+ Bug reports and pull requests are welcome on GitHub at
183
+ https://github.com/codevise/krant. This project is intended to be a
184
+ safe, welcoming space for collaboration, and contributors are expected
185
+ to adhere to the
186
+ [Contributor Covenant](http://contributor-covenant.org) code of
187
+ conduct.
188
+
189
+ ## License
190
+
191
+ The gem is available as open source under the terms of the
192
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'semmy'
4
+ Semmy::Tasks.install
@@ -0,0 +1,56 @@
1
+ module Krant
2
+ ActiveAdmin.register BroadcastMessage, as: 'BroadcastMessage' do
3
+ menu priority: 100
4
+
5
+ actions :index, :new, :create, :edit, :update, :destroy
6
+
7
+ config.batch_actions = false
8
+ config.filters = false
9
+
10
+ index do
11
+ column :text do |broadcast_message|
12
+ div do
13
+ broadcast_message.translations.each do |t|
14
+ div class: 'krant-broadcast-messages-table-text' do
15
+ span "#{t.locale}:", class: 'krant-broadcast-messages-table-text-locale'
16
+ span t.text, class: 'krant-broadcast-messages-table-text-translation'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ column :active
22
+ column :updated_at
23
+ column :created_at
24
+ actions
25
+ end
26
+
27
+ form do |f|
28
+ f.inputs do
29
+ f.input :active
30
+
31
+ f.semantic_fields_for :translations do |t|
32
+ t.input(:text,
33
+ as: :string,
34
+ label: I18n.t('krant.admin.broadcast_messages.text_translation_label',
35
+ locale_name: t.object.locale))
36
+ t.input :locale, as: :hidden
37
+ end
38
+ end
39
+ f.actions
40
+ end
41
+
42
+ after_build do |broadcast_message|
43
+ Krant.broadcast_message_locales.each do |locale|
44
+ broadcast_message.translations.detect do |t|
45
+ t.locale == locale.to_s
46
+ end || broadcast_message.translations.build(locale: locale)
47
+ end
48
+ end
49
+
50
+ controller do
51
+ def permitted_params
52
+ params.permit(broadcast_message: [:active, translations_attributes: [:id, :text, :locale]])
53
+ end
54
+ end
55
+ end
56
+ end