magazine 0.0.1

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 (99) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/javascripts/magazine/application.js +13 -0
  6. data/app/assets/stylesheets/magazine/application.css +15 -0
  7. data/app/controllers/magazine/application_controller.rb +4 -0
  8. data/app/controllers/magazine/articles_controller.rb +56 -0
  9. data/app/controllers/magazine/articles_controller.rb~ +55 -0
  10. data/app/helpers/magazine/application_helper.rb +30 -0
  11. data/app/helpers/magazine/application_helper.rb~ +30 -0
  12. data/app/models/magazine/data.rb~ +40 -0
  13. data/app/models/magazine/rack.rb +40 -0
  14. data/app/models/magazine/rack.rb~ +40 -0
  15. data/app/views/layouts/magazine/application.html.erb +14 -0
  16. data/config/routes.rb +5 -0
  17. data/config/routes.rb~ +5 -0
  18. data/lib/magazine.rb +8 -0
  19. data/lib/magazine.rb~ +8 -0
  20. data/lib/magazine/engine.rb +12 -0
  21. data/lib/magazine/engine.rb~ +13 -0
  22. data/lib/magazine/version.rb +3 -0
  23. data/lib/tasks/magazine_tasks.rake +4 -0
  24. data/spec/dummy/README.rdoc +28 -0
  25. data/spec/dummy/Rakefile +6 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +9 -0
  29. data/spec/dummy/app/controllers/application_controller.rb~ +5 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/spec/dummy/app/views/magazine/articles/index.html.erb +23 -0
  33. data/spec/dummy/app/views/magazine/articles/index.html.erb~ +23 -0
  34. data/spec/dummy/app/views/magazine/articles/shared/_list_article.html.erb +1 -0
  35. data/spec/dummy/app/views/magazine/articles/shared/_list_article.html.erb~ +1 -0
  36. data/spec/dummy/app/views/magazine/articles/shared/beans/_kilimanjaro.html.erb +1 -0
  37. data/spec/dummy/app/views/magazine/articles/shared/beans/_kilimanjaro.html.erb~ +0 -0
  38. data/spec/dummy/app/views/magazine/articles/shared/drip/_water.html.erb +1 -0
  39. data/spec/dummy/app/views/magazine/articles/shared/drip/_water.html.erb~ +0 -0
  40. data/spec/dummy/app/views/magazine/articles/show.html.erb +6 -0
  41. data/spec/dummy/app/views/magazine/articles/show.html.erb~ +6 -0
  42. data/spec/dummy/app/views/magazine/index.html.erb~ +7 -0
  43. data/spec/dummy/bin/bundle +3 -0
  44. data/spec/dummy/bin/rails +4 -0
  45. data/spec/dummy/bin/rake +4 -0
  46. data/spec/dummy/config.ru +4 -0
  47. data/spec/dummy/config/application.rb +23 -0
  48. data/spec/dummy/config/boot.rb +5 -0
  49. data/spec/dummy/config/database.yml +25 -0
  50. data/spec/dummy/config/environment.rb +5 -0
  51. data/spec/dummy/config/environments/development.rb +37 -0
  52. data/spec/dummy/config/environments/production.rb +78 -0
  53. data/spec/dummy/config/environments/test.rb +39 -0
  54. data/spec/dummy/config/initializers/assets.rb +8 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  57. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  58. data/spec/dummy/config/initializers/inflections.rb +16 -0
  59. data/spec/dummy/config/initializers/magazine.rb +1 -0
  60. data/spec/dummy/config/initializers/magazine.rb~ +0 -0
  61. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  62. data/spec/dummy/config/initializers/session_store.rb +3 -0
  63. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/spec/dummy/config/locales/en.yml +23 -0
  65. data/spec/dummy/config/magazine.yml +48 -0
  66. data/spec/dummy/config/magazine.yml~ +48 -0
  67. data/spec/dummy/config/routes.rb +3 -0
  68. data/spec/dummy/config/routes.rb~ +4 -0
  69. data/spec/dummy/config/secrets.yml +22 -0
  70. data/spec/dummy/db/test.sqlite3 +0 -0
  71. data/spec/dummy/log/development.log +0 -0
  72. data/spec/dummy/log/test.log +1180 -0
  73. data/spec/dummy/public/404.html +67 -0
  74. data/spec/dummy/public/422.html +67 -0
  75. data/spec/dummy/public/500.html +66 -0
  76. data/spec/dummy/public/favicon.ico +0 -0
  77. data/spec/dummy/tmp/cache/assets/test/sprockets/13ef700ed1b340ce31710c628c9b1506 +0 -0
  78. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  79. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  80. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  81. data/spec/dummy/tmp/cache/assets/test/sprockets/3c36df6af1863f67917951036d1d7221 +0 -0
  82. data/spec/dummy/tmp/cache/assets/test/sprockets/5bf1895db17a04b83c2f8c9bd096ca85 +0 -0
  83. data/spec/dummy/tmp/cache/assets/test/sprockets/7f4ca612f398e7c52f7fd934cddbaa50 +0 -0
  84. data/spec/dummy/tmp/cache/assets/test/sprockets/b9d7ea8e2449bbec7d43b6518403dc6c +0 -0
  85. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  86. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  87. data/spec/dummy/tmp/cache/assets/test/sprockets/ed792a88666afd4aff94594da589930e +0 -0
  88. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  89. data/spec/features/magazine/articles_spec.rb +109 -0
  90. data/spec/features/magazine/articles_spec.rb~ +109 -0
  91. data/spec/models/magazine/data.rb~ +5 -0
  92. data/spec/models/magazine/data_spec.rb~ +12 -0
  93. data/spec/models/magazine/rack_spec.rb +173 -0
  94. data/spec/models/magazine/rack_spec.rb~ +173 -0
  95. data/spec/rails_helper.rb +38 -0
  96. data/spec/rails_helper.rb~ +39 -0
  97. data/spec/spec_helper.rb +85 -0
  98. data/spec/spec_helper.rb~ +86 -0
  99. metadata +306 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b0c51b05a82ccca183673a87020e795a4a9dbcad
4
+ data.tar.gz: 3e01cba679becf02203c9e5992cc3820c3be240d
5
+ SHA512:
6
+ metadata.gz: a26c1c6cbf8f89e22d0de34e17d5be1d04b6b370c1041b37aca15abe92d8f98d67821a9c5d5c43e5130c64cb5414a620500494212f41cba1ec7617a8665ba5a2
7
+ data.tar.gz: 9f21b4f6a08f207ea687a248b187566b55bd9f0dd40afb23911cf9ae88135309ff71d3f558869fb10b864ad1aebcb4074a6b0b566dab7f22f0d4af843cf7c35c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Magazine
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Magazine'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
25
+
26
+ require 'rspec/core'
27
+ require 'rspec/core/rake_task'
28
+
29
+ desc "Run all specs in spec directory (excluding plugin specs)"
30
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
31
+
32
+ task :default => :spec
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Magazine
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,56 @@
1
+ module Magazine
2
+ class ArticlesController < ::ApplicationController
3
+ helper Magazine::ApplicationHelper
4
+ before_action :set_magazine_rack
5
+ helper_method :article_in_review?
6
+
7
+ # GET /mount_point(/:category_slug)
8
+ def index
9
+ find_category(params[:category_slug])
10
+ end
11
+
12
+ # GET /mount_point/:category_slug/:article_slug
13
+ def show
14
+ find_article(params[:category_slug], params[:article_slug])
15
+ end
16
+
17
+ private
18
+ def find_category(category_slug = '')
19
+ category_slug = params[:category_slug] if category_slug.blank?
20
+
21
+ @category = @magazine_rack.find_category(category_slug)
22
+
23
+ not_found if @category.nil? && category_slug.present?
24
+ end
25
+
26
+ def find_article(category_slug = '', article_slug = '')
27
+ category_slug = params[:category_slug] if category_slug.blank?
28
+ article_slug = params[:article_slug] if article_slug.blank?
29
+
30
+ @category = @magazine_rack.find_category(category_slug)
31
+ @article = @magazine_rack.find_article(category_slug, article_slug)
32
+
33
+ not_found if @article.nil? || article_in_review?(@article)
34
+ end
35
+
36
+ def set_magazine_rack
37
+ @magazine_rack = Magazine::Rack.new
38
+ end
39
+
40
+ def article_in_review?(article)
41
+ !(!article.review || (article.review && authorize))
42
+ end
43
+
44
+ def not_found
45
+ raise ActionController::RoutingError.new('Not found magazine article')
46
+ end
47
+
48
+ def authorize
49
+ if Magazine.authorize_method_name.present?
50
+ send(Magazine.authorize_method_name)
51
+ else
52
+ true
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,55 @@
1
+ module Magazine
2
+ class ArticlesController < ::ApplicationController
3
+ before_action :set_magazine_rack
4
+ helper_method :article_in_review?
5
+
6
+ # GET /mount_point(/:category_slug)
7
+ def index
8
+ find_category(params[:category_slug])
9
+ end
10
+
11
+ # GET /mount_point/:category_slug/:article_slug
12
+ def show
13
+ find_article(params[:category_slug], params[:article_slug])
14
+ end
15
+
16
+ private
17
+ def find_category(category_slug = '')
18
+ category_slug = params[:category_slug] if category_slug.blank?
19
+
20
+ @category = @magazine_rack.find_category(category_slug)
21
+
22
+ not_found if @category.nil? && category_slug.present?
23
+ end
24
+
25
+ def find_article(category_slug = '', article_slug = '')
26
+ category_slug = params[:category_slug] if category_slug.blank?
27
+ article_slug = params[:article_slug] if article_slug.blank?
28
+
29
+ @category = @magazine_rack.find_category(category_slug)
30
+ @article = @magazine_rack.find_article(category_slug, article_slug)
31
+
32
+ not_found if @article.nil? || article_in_review?(@article)
33
+ end
34
+
35
+ def set_magazine_rack
36
+ @magazine_rack = Magazine::Rack.new
37
+ end
38
+
39
+ def article_in_review?(article)
40
+ !(!article.review || (article.review && authorize))
41
+ end
42
+
43
+ def not_found
44
+ raise ActionController::RoutingError.new('Not found magazine article')
45
+ end
46
+
47
+ def authorize
48
+ if Magazine.authorize_method_name.present?
49
+ send(Magazine.authorize_method_name)
50
+ else
51
+ true
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ module Magazine
2
+ module ApplicationHelper
3
+ def magazine_image_tag(path, options = {})
4
+ image_tag(magazine_image_path(path, options), options.except(:category, 'category'))
5
+ end
6
+
7
+ def magazine_image_path(path, options = {})
8
+ category = _magazine_val(:category, options)
9
+ article = _magazine_val(:article, options)
10
+
11
+ image_path(['magazine', category.try(:category_slug), article.try(:slug), path].compact.join('/'))
12
+ end
13
+
14
+ def magazine_partial_path(name = nil, options = {})
15
+ category = _magazine_val(:category, options)
16
+ article = _magazine_val(:article, options)
17
+
18
+ ['magazine', 'articles', 'shared', category.try(:category_slug), article.try(:slug), name].compact.join('/')
19
+ end
20
+
21
+ private
22
+ def _magazine_val(name, options)
23
+ val = nil
24
+ val = instance_variable_get("@#{ name }") if instance_variable_get("@#{ name }").present?
25
+ val = options[name.to_sym] if options[name.to_sym].present?
26
+ val = options[name.to_s] if options[name.to_s].present?
27
+ val
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Magazine
2
+ module ApplicationHelper
3
+ def magazine_image_tag(path, options = {})
4
+ image_tag(magazine_image_path(path, options), options.except(:category, 'category'))
5
+ end
6
+
7
+ def magazine_image_path(path, options = {})
8
+ category = _magazine_val(:category, options)
9
+ article = _magazine_val(:article, options)
10
+
11
+ image_path(['magazine', category.try(:category_slug), article.try(:slug), path].compact.join('/'))
12
+ end
13
+
14
+ def magazine_partial_path(name = nil, options = {})
15
+ category = _magazine_val(:category, options)
16
+ article = _magazine_val(:article, options)
17
+
18
+ ['magazine', 'articles', 'shared', category.try(:category_slug), article.try(:slug), name].compact.join('/')
19
+ end
20
+
21
+ private
22
+ def _magazine_val(name, options)
23
+ val = nil
24
+ val = instance_variable_get("@#{ name }") if instance_variable_get("@#{ name }").present?
25
+ val = options[name.to_sym] if options[name.to_sym].present?
26
+ val = options[name.to_s] if options[name.to_s].present?
27
+ val
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ module Magazine
2
+ class Data
3
+ attr_reader :data
4
+
5
+ class << self
6
+ def config_file
7
+ Rails.root.join('config/magazine.yml')
8
+ end
9
+ end
10
+
11
+ def initialize
12
+ load_config
13
+ end
14
+
15
+ def load_config
16
+ @data = YAML.load(Data.config_file.read).map{ |datum|
17
+ ::Hashie::Mash.new(datum)
18
+ }
19
+ end
20
+
21
+ def find_category(category_slug)
22
+ @data.find{ |datum| datum.category_slug == category_slug }
23
+ end
24
+
25
+ def find_article(category_slug, article_slug)
26
+ category = find_category(category_slug)
27
+ return nil if category.nil?
28
+ category.articles.find{ |article| article.slug == article_slug }
29
+ end
30
+
31
+ def all_articles_with_category
32
+ data.inject({}) do |result, category|
33
+ category.articles.each do |article|
34
+ result[article] = category.except(:articles)
35
+ end
36
+ result
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module Magazine
2
+ class Rack
3
+ attr_reader :data
4
+
5
+ class << self
6
+ def config_file
7
+ Rails.root.join('config/magazine.yml')
8
+ end
9
+ end
10
+
11
+ def initialize
12
+ load_config
13
+ end
14
+
15
+ def load_config
16
+ @data = YAML.load(Rack.config_file.read).map{ |datum|
17
+ ::Hashie::Mash.new(datum)
18
+ }
19
+ end
20
+
21
+ def find_category(category_slug)
22
+ @data.find{ |datum| datum.category_slug == category_slug }
23
+ end
24
+
25
+ def find_article(category_slug, article_slug)
26
+ category = find_category(category_slug)
27
+ return nil if category.nil?
28
+ category.articles.find{ |article| article.slug == article_slug }
29
+ end
30
+
31
+ def all_articles_with_category
32
+ data.inject({}) do |result, category|
33
+ category.articles.each do |article|
34
+ result[article] = category.except(:articles)
35
+ end
36
+ result
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ module Magazine
2
+ class Rack
3
+ attr_reader :data
4
+
5
+ class << self
6
+ def config_file
7
+ Rails.root.join('config/magazine.yml')
8
+ end
9
+ end
10
+
11
+ def initialize
12
+ load_config
13
+ end
14
+
15
+ def load_config
16
+ @data = YAML.load(Rack.config_file.read).map{ |datum|
17
+ ::Hashie::Mash.new(datum)
18
+ }
19
+ end
20
+
21
+ def find_category(category_slug)
22
+ @data.find{ |datum| datum.category_slug == category_slug }
23
+ end
24
+
25
+ def find_article(category_slug, article_slug)
26
+ category = find_category(category_slug)
27
+ return nil if category.nil?
28
+ category.articles.find{ |article| article.slug == article_slug }
29
+ end
30
+
31
+ def all_articles_with_category
32
+ data.inject({}) do |result, category|
33
+ category.articles.each do |article|
34
+ result[article] = category.except(:articles)
35
+ end
36
+ result
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Magazine</title>
5
+ <%= stylesheet_link_tag "magazine/application", media: "all" %>
6
+ <%= javascript_include_tag "magazine/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Magazine::Engine.routes.draw do
2
+ root to: 'articles#index'
3
+ get ':category_slug', to: 'articles#index', as: :category_index
4
+ get ':category_slug/:article_slug', to: 'articles#show', as: :article
5
+ end
data/config/routes.rb~ ADDED
@@ -0,0 +1,5 @@
1
+ Magazine::Engine.routes.draw do
2
+ root to: 'articles#index'
3
+ get ':category_slug', to: 'articles#index', as: :category_index
4
+ get ':category_slug/:article_slug', to: 'articles#show', as: :magazine_article
5
+ end
data/lib/magazine.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+ require 'hashie'
3
+
4
+ require 'magazine/engine'
5
+
6
+ module Magazine
7
+ mattr_accessor :authorize_method_name
8
+ end