hakuna-metatags 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 (49) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/helpers/metatags_helper.rb +5 -0
  6. data/app/views/application/_title_and_meta_tags.html.erb +32 -0
  7. data/config/locales/metatags.yml +5 -0
  8. data/lib/metatags.rb +9 -0
  9. data/lib/metatags/base_metatags.rb +92 -0
  10. data/lib/metatags/concerns/controller.rb +138 -0
  11. data/lib/metatags/engine.rb +4 -0
  12. data/lib/metatags/version.rb +3 -0
  13. data/lib/tasks/metatags_tasks.rake +4 -0
  14. data/test/dummy/README.rdoc +28 -0
  15. data/test/dummy/Rakefile +6 -0
  16. data/test/dummy/app/assets/javascripts/application.js +13 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  18. data/test/dummy/app/controllers/application_controller.rb +5 -0
  19. data/test/dummy/app/helpers/application_helper.rb +2 -0
  20. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/test/dummy/bin/bundle +3 -0
  22. data/test/dummy/bin/rails +4 -0
  23. data/test/dummy/bin/rake +4 -0
  24. data/test/dummy/bin/setup +29 -0
  25. data/test/dummy/config.ru +4 -0
  26. data/test/dummy/config/application.rb +26 -0
  27. data/test/dummy/config/boot.rb +5 -0
  28. data/test/dummy/config/database.yml +25 -0
  29. data/test/dummy/config/environment.rb +5 -0
  30. data/test/dummy/config/environments/development.rb +41 -0
  31. data/test/dummy/config/environments/production.rb +79 -0
  32. data/test/dummy/config/environments/test.rb +42 -0
  33. data/test/dummy/config/initializers/assets.rb +11 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  36. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/test/dummy/config/initializers/inflections.rb +16 -0
  38. data/test/dummy/config/initializers/mime_types.rb +4 -0
  39. data/test/dummy/config/initializers/session_store.rb +3 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +23 -0
  42. data/test/dummy/config/routes.rb +56 -0
  43. data/test/dummy/config/secrets.yml +22 -0
  44. data/test/dummy/public/404.html +67 -0
  45. data/test/dummy/public/422.html +67 -0
  46. data/test/dummy/public/500.html +66 -0
  47. data/test/dummy/public/favicon.ico +0 -0
  48. data/test/test_helper.rb +20 -0
  49. metadata +156 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86a12bcdd72d0cecfcdaae5b9630e23fec616268
4
+ data.tar.gz: fe34e8e1d46282511b47680c394fbfbded2c12b0
5
+ SHA512:
6
+ metadata.gz: 50c5957dd1dc6f0debd89be10b4b453d32ace903f675bac2d2bf17666457b2d167e38b3ee80ea82115869410623b7ec5c87331ea9733b8b22106238086648980
7
+ data.tar.gz: be2748c7494c81242c2a6aa9ddc7d4a8a152bdfbac867fa1e4e7a641b926468ad0198037707c6c2700bb5e6f8185984a51210ce22ea411710701a76cdf37db1d
@@ -0,0 +1,20 @@
1
+ Copyright 2016 niuage
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.
@@ -0,0 +1,3 @@
1
+ = Metatags
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,34 @@
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 = 'Metatags'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,5 @@
1
+ module MetatagsHelper
2
+ def render_meta_tags
3
+ render meta_tags
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ <title><%= meta_tags.title %></title>
2
+ <%= tag :meta, name: "description", content: meta_tags.description %>
3
+
4
+ <%# OpenGraph %>
5
+ <%= tag :meta, name: "og:title", content: meta_tags.title %>
6
+ <%= tag :meta, name: "og:type", content: meta_tags.type %>
7
+ <%= tag :meta, name: "og:description", content: meta_tags.description %>
8
+ <%= tag :meta, name: "og:url", content: meta_tags.url %>
9
+ <%= tag :meta, name: "og:image", content: meta_tags.image %>
10
+
11
+ <%# Twitter %>
12
+ <%= tag :meta, name: "twitter:card", content: meta_tags.twitter_card %>
13
+ <%= tag :meta, name: "twitter:title", content: meta_tags.title %>
14
+ <%= tag :meta, name: "twitter:description", content: meta_tags.description %>
15
+ <%= tag :meta, name: "twitter:url", content: meta_tags.twitter_url %>
16
+ <%= tag :meta, name: "twitter:site", content: meta_tags.twitter_site %>
17
+ <%= tag :meta, name: "twitter:image", content: meta_tags.image %>
18
+ <%= tag :meta, name: "twitter:creator", content: meta_tags.twitter_creator %>
19
+
20
+ <%# Google+ tags %>
21
+ <%= tag :meta, itemprop: "name", content: meta_tags.title %>
22
+ <%= tag :meta, itemprop: "description", content: meta_tags.description %>
23
+ <%= tag :meta, itemprop: "image", content: meta_tags.image %>
24
+
25
+ <%# Facebook %>
26
+ <% if meta_tags.facebook_app_id %>
27
+ <%= tag :meta, name: "fb:app_id", content: meta_tags.facebook_app_id %>
28
+ <% end %>
29
+
30
+ <%# Others %>
31
+ <%= tag :meta, name: "robots", content: meta_tags.robots %>
32
+ <%= tag :meta, name: "theme-color", content: meta_tags.theme_color %>
@@ -0,0 +1,5 @@
1
+ en:
2
+ meta_tags:
3
+ base:
4
+ title: ""
5
+ description: ""
@@ -0,0 +1,9 @@
1
+ require "metatags/engine"
2
+
3
+ require "metatags/version"
4
+
5
+ require "metatags/base_metatags"
6
+ require "metatags/concerns/controller"
7
+
8
+ module Metatags
9
+ end
@@ -0,0 +1,92 @@
1
+ #
2
+ # BaseMetatags contains all the default values for the page title, page description,
3
+ # and meta tags.
4
+ #
5
+ # This class, or one of its descendants, is instanciated on every page.
6
+ #
7
+ # If a new page requires different meta tags, create a new subclass, and override
8
+ # the necessary methods.
9
+ #
10
+
11
+ module Metatags
12
+ class BaseMetatags
13
+ attr_accessor :object, :view_context
14
+
15
+ delegate :image_url, :request, to: :view_context
16
+
17
+ def initialize(object, view_context)
18
+ self.object = object
19
+ self.view_context = view_context
20
+ end
21
+
22
+ def title
23
+ I18n.translate("title", with_scope(i18n_title_data))
24
+ end
25
+
26
+ def description
27
+ I18n.translate("description", with_scope(i18n_description_data))
28
+ end
29
+
30
+ def url
31
+ request.original_url
32
+ end
33
+ alias_method :twitter_url, :url
34
+
35
+ def image
36
+ meta_tag_image_url("og-main.jpg")
37
+ end
38
+
39
+ def type
40
+ "devpost:website"
41
+ end
42
+
43
+ def to_partial_path
44
+ "title_and_meta_tags"
45
+ end
46
+
47
+ def twitter_card
48
+ "summary_large_image"
49
+ end
50
+
51
+ def twitter_site
52
+ "@devpost"
53
+ end
54
+
55
+ def twitter_creator
56
+ end
57
+
58
+ def facebook_app_id
59
+ end
60
+
61
+ def robots
62
+ end
63
+
64
+ def theme_color
65
+ end
66
+
67
+ def i18n_scope
68
+ "meta_tags.#{object_class_name.underscore}"
69
+ end
70
+
71
+ def with_scope(data)
72
+ (data || {}).merge({ scope: i18n_scope })
73
+ end
74
+
75
+ def i18n_title_data
76
+ {}
77
+ end
78
+
79
+ def i18n_description_data
80
+ {}
81
+ end
82
+
83
+ def meta_tag_image_url(image_name)
84
+ image_url("meta_tags/#{image_name}")
85
+ end
86
+
87
+ def object_class_name
88
+ return self.class.name.gsub(/Metatags(::)?/, "") if object.blank?
89
+ object.class.name.split("::").last
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,138 @@
1
+ # Example:
2
+ #
3
+ # class ApplicationController < ActionController::Base
4
+ # include Metatags::Concerns::Controller
5
+ # end
6
+ #
7
+ # class ArticlesController < ApplicationController
8
+ # before_action :find_article, only: [:show]
9
+ #
10
+ # # Simplest option.
11
+ # # Will use Metatags::ArticleMetatags by default.
12
+ # build_meta_tags instance: :article
13
+ # # OR
14
+ # # if you need to be specific about which class to use
15
+ # build_meta_tags with: Metatags::CustomArticleMetatags, instance: :article
16
+ # # OR
17
+ # # if you need logic to determine which Metatags class to use, and want to build
18
+ # # the meta tags in the action itself.
19
+ # skip_building_metatags only: [:index]
20
+ #
21
+ # def index
22
+ # @articles = Article.all
23
+ # end
24
+ #
25
+ # def show
26
+ # end
27
+ #
28
+ # protected
29
+ #
30
+ # def find_article
31
+ # @article = Article.find(params[:id])
32
+ # end
33
+ # end
34
+
35
+ module Metatags
36
+ module Concerns
37
+ module Controller
38
+ extend ActiveSupport::Concern
39
+
40
+ included do
41
+ class_attribute :metatags_class, :metatags_instance_sym
42
+ initialize_metatags_class
43
+
44
+ before_action :build_default_meta_tags
45
+
46
+ attr_accessor :meta_tags
47
+ helper_method :meta_tags
48
+ end
49
+
50
+ module ClassMethods
51
+
52
+ ## Example:
53
+ #
54
+ # class TeamsController
55
+ # build_meta_tags with: Metatags::TeamMetatags, instance: :team
56
+ # end
57
+ #
58
+ ## The code above will build an instance of the Metatags::TeamMetatags class
59
+ ## with `@team` if present.
60
+ #
61
+ def build_meta_tags(options = {})
62
+ self.metatags_class = options.delete(:with)
63
+ self.metatags_instance_sym = options.delete(:instance)
64
+
65
+ skip_before_action :build_default_meta_tags, options
66
+ before_action :build_meta_tags_with_instance, options
67
+ end
68
+
69
+ def skip_building_meta_tags(options = {})
70
+ skip_before_action :build_default_meta_tags, options
71
+ end
72
+
73
+ def initialize_metatags_class
74
+ self.metatags_class = "Metatags::AppMetatags".safe_constantize || Metatas::BaseMetatags
75
+ end
76
+ end
77
+
78
+ protected
79
+
80
+ # Builds the meta_tags using either the class passed by the user with the `with`
81
+ # option or a class which name is inferred from the controller name.
82
+ #
83
+ def build_default_meta_tags
84
+ klass = metatags_class || default_metatags_class
85
+ build_meta_tags(with: klass, instance: metatags_instance)
86
+ end
87
+ alias_method :build_meta_tags_with_instance, :build_default_meta_tags
88
+
89
+ def metatags_instance
90
+ return nil unless metatags_instance_sym
91
+ instance_variable_get("@#{metatags_instance_sym}")
92
+ end
93
+
94
+ # Infers the metatags class name from the controller name by default.
95
+ #
96
+ # The default class can be overriden with the `with` option of `build_meta_tags`
97
+ #
98
+ def default_metatags_class
99
+ inferred_name = self.class.name.gsub("Controller", "").singularize
100
+
101
+ [
102
+ # Metatags::Manage::TeamMetatags::Index
103
+ "Metatags::#{inferred_name}Metatags::#{action_name.classify}",
104
+ # Metatags::Manage::TeamMetatags
105
+ "Metatags::#{inferred_name}Metatags",
106
+ # Metatags::TeamMetatags::Index
107
+ "Metatags::#{inferred_name.split("::").last}Metatags::#{action_name.classify}",
108
+ # Metatags::TeamMetatags
109
+ "Metatags::#{inferred_name.split("::").last}Metatags",
110
+ # Metatags::AppMetatags
111
+ "Metatags::AppMetatags",
112
+ # Metatags::BaseMetatags
113
+ "Metatags::BaseMetatags"
114
+ ].detect do |class_name|
115
+ klass = class_name.safe_constantize
116
+ break klass if klass
117
+ end
118
+ end
119
+
120
+ # This method is useful when the class name of the Metatags class cannot
121
+ # be inferred by the gem.
122
+ #
123
+ # Ex:
124
+ #
125
+ # class TeamsController
126
+ # def show
127
+ # if special_case?
128
+ # build_meta_tags with: Metatags::SpecialMetatags, instance: :team
129
+ # end
130
+ # end
131
+ # end
132
+ #
133
+ def build_meta_tags(with: Metatags::BaseMetatags, instance: nil)
134
+ self.meta_tags = with.new(instance, view_context)
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,4 @@
1
+ module Metatags
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Metatags
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :metatags do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -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 any plugin's vendor/assets/javascripts directory 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/rails/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 any plugin's vendor/assets/stylesheets directory 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,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end