meta-tags 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a951b5f1a98a69eeea2e13cc53fcea808f44ef08
4
- data.tar.gz: b9bf8e2f0ca386108cb7108d13b8909ba2ccc1b3
3
+ metadata.gz: bcbe8d42f7548699bb2a370c45a5a0bd28bda93c
4
+ data.tar.gz: 490acebe6d35cd7890787012e4b9eea11f567c0a
5
5
  SHA512:
6
- metadata.gz: 588b6a8f83d32e391b72b063f17983509821e4ad896be1ece4698f00f40d6aee2dd93cb8cf82b796201d52e796451a9ac0f657c42168b6c36612b1949cb6d1c6
7
- data.tar.gz: a05a64fa12af04a87a5161b60b1874c3715b6d98b4df6eacbfa8d7f752bb23401a39f8eb10258edad59928f3dadfee07bcc8c7e9f2488f218f6e4dc7fef02b2a
6
+ metadata.gz: f644c35dd746b09bfdb3c2c25d656d43ced607b91b30327d165952f49c3a569b5def2f8af0fbb20a455fd81faf3114089a579206e6289fdfaf08ce96e480c1dc
7
+ data.tar.gz: 7fe7416185f75d3d5bc04a3dceafe77944e41d2a57639ebeb5c4ace7035b59ec1b951d865f4490353cd38b36ab81a43460bea196199e405f05c6c013e3b5ad8e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -719,7 +719,7 @@ Style/LineEndConcatenation:
719
719
  line end.
720
720
  Enabled: false
721
721
 
722
- Style/MethodCallWithoutArgsParentheses:
722
+ Style/MethodCallParentheses:
723
723
  Description: 'Do not use parentheses for method calls with no arguments.'
724
724
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
725
725
  Enabled: true
@@ -838,7 +838,7 @@ Style/ParallelAssignment:
838
838
  matches on both sides of the assignment.
839
839
  This also provides performance benefits
840
840
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment'
841
- Enabled: true
841
+ Enabled: false
842
842
 
843
843
  Style/ParenthesesAroundCondition:
844
844
  Description: >-
@@ -1,3 +1,18 @@
1
+ ## 2.6.0 (August 24, 2017) [☰](https://github.com/kpumuk/meta-tags/compare/v2.5.0...v2.6.0)
2
+
3
+ Features:
4
+ - Optionally avoid downcasing keywords
5
+ - Added Rails generator to create an initializer with the default settings.
6
+ - Added a configuration option `truncate_site_title_first` which enables site title truncation when title limit is reached.
7
+ - When `Time`, `Date`, or `DateTime` passed as a meta tag value, it will be formatted according to ISO 8601.
8
+
9
+ Bugfixes:
10
+ - When title limit reached with `reverse` set to `true`, properly truncate the last item of the title array instead of the first one.
11
+ - Do not merge title and site title for OpenGraph, site title is available for reference as `:site`, and full title as `:full_title`.
12
+
13
+ Changes:
14
+ - Removed Google "author" and "publisher" links, as Google deprecated these options (https://support.google.com/webmasters/answer/6083347?hl=en)
15
+
1
16
  ## 2.5.0 (August 23, 2017) [☰](https://github.com/kpumuk/meta-tags/compare/v2.4.1...v2.5.0)
2
17
 
3
18
  Features:
@@ -27,8 +42,6 @@ Changes:
27
42
  Features:
28
43
  - Added support for article meta tags
29
44
 
30
- Bugfixes:
31
-
32
45
  ## 2.2.0 (August 24, 2016) [☰](https://github.com/kpumuk/meta-tags/compare/v2.1.0...v2.2.0)
33
46
 
34
47
  Changes:
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ 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, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at kpumuk@kpumuk.info. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,52 @@
1
+ # Contributing
2
+
3
+ We love pull requests from everyone. By participating in this project, you
4
+ agree to abide by the [code of conduct](https://github.com/kpumuk/meta-tags/blob/master/CODE_OF_CONDUCT.md).
5
+
6
+ ## Configuring Development Environment
7
+
8
+ Fork, then clone the repo:
9
+
10
+ git clone git@github.com:your-username/meta-tags.git
11
+
12
+ Set up your machine:
13
+
14
+ ./bin/setup
15
+
16
+ Make sure the tests pass:
17
+
18
+ rake
19
+
20
+ ## Contributing a Code Change
21
+
22
+ Make your change. Add tests for your change. Make the tests pass:
23
+
24
+ rake
25
+
26
+ ## Fixing a Meta Tag to Use `property` Argument
27
+
28
+ [HTML standard](https://www.w3schools.com/TAgs/tag_meta.asp) states that the
29
+ argument for the meta tag name should be `name`:
30
+
31
+ ```html
32
+ <meta name="keywords" content="HTML,CSS,XML,JavaScript">
33
+ ```
34
+
35
+ Some social networks require to use `property` argument instead (Facebook Open Graph).
36
+ MetaTags supports the most popular meta tags, but there will be tags that are not covered
37
+ by default. If you found one, and you feel like the community would benefit from
38
+ MetaTags supporting it out of the box, feel free to add it to [the list](https://github.com/kpumuk/meta-tags/blob/master/lib/meta_tags/configuration.rb#L23-L57)
39
+ and submit a pull request.
40
+
41
+ ## Raising a Pull Request
42
+
43
+ Push to your fork and [submit a pull request](https://github.com/kpumuk/meta-tags/compare/).
44
+
45
+ At this point you're waiting on us. We like to at least comment on pull requests
46
+ within couple days. We may suggest some changes or improvements or alternatives.
47
+
48
+ Some things that will increase the chance that your pull request is accepted:
49
+
50
+ * Write tests.
51
+ * Make sure [CodeClimate](https://codeclimate.com/github/kpumuk/meta-tags/builds) build is clean.
52
+ * Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
data/Gemfile CHANGED
@@ -3,7 +3,9 @@ source 'http://rubygems.org'
3
3
  # Specify your gem's dependencies in meta-tags.gemspec
4
4
  gemspec
5
5
 
6
- if ENV['RAILS_VERSION']
6
+ if ENV['RAILS_VERSION'] == 'edge'
7
+ gem 'actionpack', git: 'https://github.com/rails/rails.git'
8
+ elsif ENV['RAILS_VERSION']
7
9
  gem 'actionpack', "~> #{ENV['RAILS_VERSION']}"
8
10
  end
9
11
 
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/meta-tags.svg)](https://badge.fury.io/rb/meta-tags)
5
5
  [![Code Climate](https://codeclimate.com/github/kpumuk/meta-tags/badges/gpa.svg)](https://codeclimate.com/github/kpumuk/meta-tags)
6
6
  [![Test Coverage](https://codeclimate.com/github/kpumuk/meta-tags/badges/coverage.svg)](https://codeclimate.com/github/kpumuk/meta-tags/coverage)
7
+ [![Gem Downloads](https://img.shields.io/gem/dt/meta-tags.svg)](https://badge.fury.io/rb/meta-tags)
7
8
 
8
9
  Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
9
10
 
@@ -31,19 +32,14 @@ And run `bundle install` command.
31
32
 
32
33
  MetaTags follows best-practices for meta tags. Although default limits for
33
34
  truncation have recommended values, you can change them to reflect your own
34
- preferences. In order to do that, you can create an initializer
35
- `config/initializers/meta_tags.rb`, with following code:
36
-
37
- ```ruby
38
- MetaTags.configure do |c|
39
- c.title_limit = 70
40
- c.description_limit = 160
41
- c.keywords_limit = 255
42
- c.keywords_separator = ', '
43
- c.property_tags.push(
44
- 'x-hearthstone:deck',
45
- )
46
- end
35
+ preferences. Keywords are converted to lowercase by default, but this is also
36
+ configurable.
37
+
38
+ To overide the defaults, create an initializer
39
+ `config/initializers/meta_tags.rb` using the following command:
40
+
41
+ ```bash
42
+ rails generate meta_tags:install
47
43
  ```
48
44
 
49
45
  By default meta tags are rendered with the key `name`. Since, some meta tags are
@@ -52,10 +48,6 @@ allows to configure which tags to render with `property` attribute. By default
52
48
  the pre-configured list includes all possible Facebook Open Graph object types, but
53
49
  you can add your own in case you need it.
54
50
 
55
- **Please note**: Use `c.property_tags.push` instead of `c.property_tags =`, so you
56
- do not reset the list of default tags, which would lead to invalid Open Graph
57
- meta tags.
58
-
59
51
  ## MetaTags Usage
60
52
 
61
53
  First, add this code to your main layout:
@@ -112,7 +104,7 @@ To set meta tags you can use following methods:
112
104
  ```erb
113
105
  <% title 'Member Login' %>
114
106
  <% description 'Member login page.' %>
115
- <% keywords 'Member login page.' %>
107
+ <% keywords 'Site, Login, Members' %>
116
108
  <% nofollow %>
117
109
  <% noindex %>
118
110
  <% refresh 3 %>
@@ -157,8 +149,6 @@ Use these options to customize the title format:
157
149
  * `:nofollow` — add nofollow meta tag; when true, 'robots' will be used, otherwise the string will be used;
158
150
  * `:follow` – add follow meta tag; when true, 'robots' will be used, otherwise the string will be used;
159
151
  * `:canonical` — add canonical link tag;
160
- * `:author` — add author link tag;
161
- * `:publisher` — add publisher link tag;
162
152
  * `:prev` — add prev link tag;
163
153
  * `:next` — add next link tag;
164
154
  * `:image_src` — add image_src link tag;
@@ -207,7 +197,8 @@ Say, you have the following in your application layout:
207
197
 
208
198
  ```ruby
209
199
  display_meta_tags og: {
210
- title: :title
200
+ title: :title,
201
+ site_name: :site,
211
202
  }
212
203
  ```
213
204
 
@@ -224,6 +215,9 @@ You get this open graph meta tag for free:
224
215
  <meta property="og:title" content="my great view"></meta>
225
216
  ```
226
217
 
218
+ Please note, that title does not include site. If you need to reference the exact
219
+ value rendered in the `<title>` meta tag, use `:full_title`.
220
+
227
221
  ### Using with Turbolinks
228
222
 
229
223
  [Turbolinks](https://github.com/turbolinks/turbolinks) is a simple solution for getting
@@ -290,6 +284,10 @@ set_meta_tags site: 'Site Title', title: 'Member Login', reverse: true
290
284
 
291
285
  Recommended title tag length: up to <b>70 characters</b>, <b>10 words</b>.
292
286
 
287
+ Further reading:
288
+
289
+ * [Title Tag](https://moz.com/learn/seo/title-tag)
290
+
293
291
  ### Description
294
292
 
295
293
  Description tags are called meta tags as they are not displayed by the
@@ -304,6 +302,10 @@ set_meta_tags description: "All text about keywords, other keywords"
304
302
 
305
303
  Recommended description tag length: up to <b>160 characters</b>.
306
304
 
305
+ Further reading:
306
+
307
+ * [Meta Description](https://moz.com/learn/seo/meta-description)
308
+
307
309
  ### Keywords
308
310
 
309
311
  Meta keywords tag are used to place your keywords that you think a
@@ -317,6 +319,9 @@ set_meta_tags keywords: %w[keyword1 Keyword2 KeyWord3]
317
319
 
318
320
  Recommended keywords tag length: up to <b>255 characters</b>, <b>20 words</b>.
319
321
 
322
+ **Please note**, that both Google and Bing publicly indicated that keywords
323
+ meta tags is completely ignored.
324
+
320
325
  ### Noindex
321
326
 
322
327
  By using the noindex meta tag, you can signal to search engines to not
@@ -407,30 +412,6 @@ Further reading:
407
412
  * [Favicon](https://www.wikiwand.com/en/Favicon)
408
413
  * [Touch Icons](https://mathiasbynens.be/notes/touch-icons)
409
414
 
410
- ### Author links
411
-
412
- Link to your Google+ profile using rel="author"
413
-
414
- ```ruby
415
- set_meta_tags author: "http://yourgplusprofile.com/profile/url"
416
- # <link rel="author" href="http://yourgplusprofile.com/profile/url" />
417
- ```
418
-
419
- Further reading:
420
-
421
- * [About rel="author"](https://support.google.com/webmasters/answer/2539557?hl=en)
422
-
423
- ### Publisher links
424
-
425
- Link to your Google+ profile using rel="publisher"
426
-
427
- ```ruby
428
- set_meta_tags publisher: "http://yourgplusprofile.com/profile/url"
429
- # <link rel="publisher" href="http://yourgplusprofile.com/profile/url" />
430
- ```
431
-
432
- * [Link to your website](https://support.google.com/plus/answer/1713826?hl=en)
433
- * [The Difference Between rel=author & rel=publisher](http://www.websitemagazine.com/content/blogs/posts/archive/2013/02/05/the-difference-between-rel-author-amp-rel-publisher.aspx)
434
415
 
435
416
  ### Multi-regional and multilingual URLs, RSS and mobile links
436
417
 
@@ -730,6 +711,6 @@ set_meta_tags author: [ "Dmytro Shteflyuk", "John Doe" ]
730
711
  # <meta name="author" content="John Doe"/>
731
712
  ```
732
713
 
733
- ## Author
714
+ ## Maintainers
734
715
 
735
716
  [Dmytro Shteflyuk](https://github.com/kpumuk), [https://kpumuk.info](http://kpumuk.info/)
@@ -1,7 +1,7 @@
1
1
  -----BEGIN CERTIFICATE-----
2
2
  MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ8wDQYDVQQDDAZrcHVt
3
3
  dWsxFjAUBgoJkiaJk/IsZAEZFgZrcHVtdWsxFDASBgoJkiaJk/IsZAEZFgRpbmZv
4
- MB4XDTE2MDgyNDAxMDYwOFoXDTE3MDgyNDAxMDYwOFowPzEPMA0GA1UEAwwGa3B1
4
+ MB4XDTE3MDgyNDE2MDUzOVoXDTE4MDgyNDE2MDUzOVowPzEPMA0GA1UEAwwGa3B1
5
5
  bXVrMRYwFAYKCZImiZPyLGQBGRYGa3B1bXVrMRQwEgYKCZImiZPyLGQBGRYEaW5m
6
6
  bzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALw2YroZc+IT+rs8NuPu
7
7
  c13DelrxrpAgPEu1zuRb3l7WaHRNWA4TyS8Z6Aa1G2O+FdUZNMW1n7IwP/QMJ9Mz
@@ -12,10 +12,10 @@ pJ3vGgO2sh5GvJFOPk1Vlur2nX9ZFznPEP1CEAQ+NFrmKRt355Z5sgOkAojSGnIL
12
12
  /1sCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFPa4
13
13
  VFc1YOlV1u/7EGTwMCAk8YE9MB0GA1UdEQQWMBSBEmtwdW11a0BrcHVtdWsuaW5m
14
14
  bzAdBgNVHRIEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wDQYJKoZIhvcNAQEFBQAD
15
- ggEBAKOnJYyA5Aq2BPQTSd9uxUzoYL010HsxIz2xFPNRxcI9wvgy6tE7noUD6yu5
16
- k/IXjQOiqMag0zGF3rdEbDFHsvDhos9xZeGUaM3YIfoYg4YF7P7HgRCQFYL7G3va
17
- h++H5FhlqFOF8g4lvYZ80AMNBO/tDfGuIzaJFbv+1mlHc2Szd3t7Mt2kNae92OYJ
18
- x9+w3/LzxW8XariFP1RBseVgHdH9JwbranEqRJ51WwJ0zTGgDnvGxOxigExXEfYE
19
- He5T3dBG5WWdIclQcE+JgohBpQ78TcVs1pFNjFmW9pC/P7Rm2GlYqOPHBQG1/Qx9
20
- ySbbrGHRLVz8DCxQbhKw+mdT5bg=
15
+ ggEBADVN1hwt6ryAPcL8DBB7wM/cYy3oVpYDO1rLGfrdEOgI/Kz+qYbp+6cx9RCY
16
+ DOY6N3GVifGBlFEuyfY3Nubx9mG0FzyBytU7Cb+u+HF3Aw/MnGRoUuY3bzxy3sVE
17
+ t9uyKLaSN0e70mipmWWHhzIZg9sXFfNNt1vLipuw8ZScyoJAa1p5AK4syX6ZAL9G
18
+ g8psHzMWdefrDNJaB8PG8BI2Nb0sIKs8HdACKZo+qDO6b+oi4Wk0nLbRH7qnJcww
19
+ QwaoNrsQi488Dsk54YiNQWVouzfjRqEa4uUxSyKmRfQp7MNILESAOCXM+wZIxanu
20
+ C9c9eUxgNTnHhsR3sK0QCIMwtUI=
21
21
  -----END CERTIFICATE-----
@@ -0,0 +1,12 @@
1
+ module MetaTags
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Copy MetaTags default files"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_config
8
+ template "config/initializers/meta_tags.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ # Use this setup block to configure all options available in MetaTags.
2
+ MetaTags.configure do |config|
3
+ # How many characters should the title meta tag have at most. Default is 70.
4
+ # Set to nil or 0 to remove limits.
5
+ # config.title_limit = 70
6
+
7
+ # When true, site title will be truncated instead of title. Default is false.
8
+ # config.truncate_site_title_first = false
9
+
10
+ # Maximum length of the page description. Default is 160.
11
+ # Set to nil or 0 to remove limits.
12
+ # config.description_limit = 160
13
+
14
+ # Maxumum length of the keywords meta tag. Default is 255.
15
+ # config.keywords_limit = 255
16
+
17
+ # Default separator for keywords meta tag (used when an Array passed with
18
+ # the list of keywords). Default is ", ".
19
+ # config.keywords_separator = ', '
20
+
21
+ # When true, keywords will be converted to lowercase, otherwise they will
22
+ # appear on the page as is. Default is true.
23
+ # config.keywords_lowercase = true
24
+
25
+ # List of additional meta tags that should use "property" attribute instead
26
+ # of "name" attribute in <meta> tags.
27
+ # config.property_tags.push(
28
+ # 'x-hearthstone:deck',
29
+ # )
30
+ end
@@ -3,15 +3,25 @@ module MetaTags
3
3
  class Configuration
4
4
  # How many characters to truncate title to.
5
5
  attr_accessor :title_limit
6
+
7
+ # Truncate site_title instead of title.
8
+ attr_accessor :truncate_site_title_first
9
+
6
10
  # How many characters to truncate description to.
7
11
  attr_accessor :description_limit
12
+
8
13
  # How many characters to truncate keywords to.
9
14
  attr_accessor :keywords_limit
15
+
10
16
  # Keywords separator - a string to join keywords with.
11
17
  attr_accessor :keywords_separator
18
+
19
+ # Should keywords forced into lowercase?
20
+ attr_accessor :keywords_lowercase
21
+
12
22
  # Custom meta tags that should use `property` attribute instead of `name`
13
23
  # - an array of strings or symbols representing their names or name-prefixes.
14
- attr_accessor :property_tags
24
+ attr_reader :property_tags
15
25
 
16
26
  # Initializes a new instance of Configuration class.
17
27
  def initialize
@@ -56,9 +66,11 @@ module MetaTags
56
66
 
57
67
  def reset_defaults!
58
68
  @title_limit = 70
69
+ @truncate_site_title_first = false
59
70
  @description_limit = 160
60
71
  @keywords_limit = 255
61
72
  @keywords_separator = ', '
73
+ @keywords_lowercase = true
62
74
  @property_tags = default_property_tags.dup
63
75
  end
64
76
  end
@@ -8,7 +8,7 @@ module MetaTags
8
8
  # @return [String] HTML string for the tag.
9
9
  #
10
10
  def render(view)
11
- view.content_tag(name, attributes[:content], attributes.except(:content))
11
+ view.content_tag(name, attributes[:content], prepare_attributes(attributes.except(:content)))
12
12
  end
13
13
  end
14
14
  end
@@ -60,6 +60,17 @@ module MetaTags
60
60
  with_defaults(defaults) { extract_full_title }
61
61
  end
62
62
 
63
+ # Constructs the title without site title (for normalized parameters).
64
+ #
65
+ # @return [String] page title.
66
+ #
67
+ def page_title(defaults = {})
68
+ old_site, @meta_tags[:site] = @meta_tags[:site], nil
69
+ with_defaults(defaults) { extract_full_title }
70
+ ensure
71
+ @meta_tags[:site] = old_site
72
+ end
73
+
63
74
  # Deletes and returns a meta tag value by name.
64
75
  #
65
76
  # @param [String, Symbol] name meta tag name.
@@ -51,8 +51,10 @@ module MetaTags
51
51
  # @param [Array<Tag>] tags a buffer object to store tag in.
52
52
  #
53
53
  def render_title(tags)
54
+ normalized_meta_tags[:title] = meta_tags.page_title
55
+ normalized_meta_tags[:site] = meta_tags[:site]
54
56
  title = meta_tags.extract_full_title
55
- normalized_meta_tags[:title] = title
57
+ normalized_meta_tags[:full_title] = title
56
58
  tags << ContentTag.new(:title, content: title) if title.present?
57
59
  end
58
60
 
@@ -145,7 +147,7 @@ module MetaTags
145
147
  # @param [Array<Tag>] tags a buffer object to store tag in.
146
148
  #
147
149
  def render_links(tags)
148
- [ :amphtml, :canonical, :prev, :next, :author, :publisher, :image_src ].each do |tag_name|
150
+ [ :amphtml, :canonical, :prev, :next, :image_src ].each do |tag_name|
149
151
  href = meta_tags.extract(tag_name)
150
152
  if href.present?
151
153
  @normalized_meta_tags[tag_name] = href
@@ -19,7 +19,15 @@ module MetaTags
19
19
  # @return [String] HTML string for the tag.
20
20
  #
21
21
  def render(view)
22
- view.tag(name, attributes)
22
+ view.tag(name, prepare_attributes(attributes))
23
+ end
24
+
25
+ protected
26
+
27
+ def prepare_attributes(attributes)
28
+ attributes.each do |key, value|
29
+ attributes[key] = value.iso8601 if value.respond_to?(:iso8601)
30
+ end
23
31
  end
24
32
  end
25
33
  end
@@ -1,6 +1,8 @@
1
1
  module MetaTags
2
2
  # Module contains helpers that normalize text meta tag values.
3
3
  module TextNormalizer
4
+ extend self
5
+
4
6
  # Normalize title value.
5
7
  #
6
8
  # @param [String] site_title site title.
@@ -9,25 +11,23 @@ module MetaTags
9
11
  # @param [true,false] reverse whether title should be reversed.
10
12
  # @return [Array<String>] array of title parts with tags removed.
11
13
  #
12
- def self.normalize_title(site_title, title, separator, reverse = false)
14
+ def normalize_title(site_title, title, separator, reverse = false)
13
15
  title = Array(title).flatten.map(&method(:strip_tags)).reject(&:blank?)
16
+ title.reverse! if reverse
17
+
14
18
  site_title = strip_tags(site_title)
15
19
  separator = strip_tags(separator)
16
20
 
17
- if MetaTags.config.title_limit
18
- limit = calculate_limit(site_title, separator)
21
+ # Truncate title and site title
22
+ site_title, title = truncate_title(site_title, title, separator)
19
23
 
20
- if limit > site_title.length
21
- title = truncate_array(title, limit - site_title.length, separator)
24
+ if site_title.present?
25
+ if reverse
26
+ title.push(site_title)
22
27
  else
23
- site_title = truncate(site_title, limit)
24
- # Site title is too long, we have to skip page title
25
- title = []
28
+ title.unshift(site_title)
26
29
  end
27
30
  end
28
-
29
- title.unshift(site_title) if site_title.present?
30
- title.reverse! if reverse
31
31
  safe_join(title, separator)
32
32
  end
33
33
 
@@ -37,7 +37,7 @@ module MetaTags
37
37
  # @return [String] text with tags removed, squashed spaces, truncated
38
38
  # to 200 characters.
39
39
  #
40
- def self.normalize_description(description)
40
+ def normalize_description(description)
41
41
  return '' if description.blank?
42
42
  description = cleanup_string(description)
43
43
  truncate(description, MetaTags.config.description_limit)
@@ -48,9 +48,10 @@ module MetaTags
48
48
  # @param [String, Array<String>] keywords list of keywords as a string or Array.
49
49
  # @return [String] list of keywords joined with comma, with tags removed.
50
50
  #
51
- def self.normalize_keywords(keywords)
51
+ def normalize_keywords(keywords)
52
52
  return '' if keywords.blank?
53
- keywords = cleanup_strings(keywords).each(&:downcase!)
53
+ keywords = cleanup_strings(keywords)
54
+ keywords.each(&:downcase!) if MetaTags.config.keywords_lowercase
54
55
  separator = strip_tags MetaTags.config.keywords_separator
55
56
 
56
57
  keywords = truncate_array(keywords, MetaTags.config.keywords_limit, separator)
@@ -61,7 +62,7 @@ module MetaTags
61
62
  #
62
63
  # @return [ActionView::Base] proxy object to access Rails helpers.
63
64
  #
64
- def self.helpers
65
+ def helpers
65
66
  ActionController::Base.helpers
66
67
  end
67
68
 
@@ -70,7 +71,7 @@ module MetaTags
70
71
  # @param [String] string HTML string.
71
72
  # @return [String] html_safe string with no HTML tags.
72
73
  #
73
- def self.strip_tags(string)
74
+ def strip_tags(string)
74
75
  if defined?(Loofah)
75
76
  # Instead of strip_tags we will use Loofah to strip tags from now on
76
77
  stripped_unescaped = Loofah.fragment(string).text(encode_special_chars: false)
@@ -89,7 +90,7 @@ module MetaTags
89
90
  # @param [String] sep separator to join strings with.
90
91
  # @return [String] input strings joined together using a given separator.
91
92
  #
92
- def self.safe_join(array, sep = $OFS)
93
+ def safe_join(array, sep = $OFS)
93
94
  helpers.safe_join(array, sep)
94
95
  end
95
96
 
@@ -99,7 +100,7 @@ module MetaTags
99
100
  # @return [String] input string with no HTML tags and consequent white
100
101
  # space characters squashed into a single space.
101
102
  #
102
- def self.cleanup_string(string)
103
+ def cleanup_string(string)
103
104
  strip_tags(string).gsub(/\s+/, ' ').strip.html_safe
104
105
  end
105
106
 
@@ -109,7 +110,7 @@ module MetaTags
109
110
  # @return [Array<String>] clean strings.
110
111
  # @see cleanup_string
111
112
  #
112
- def self.cleanup_strings(strings)
113
+ def cleanup_strings(strings)
113
114
  Array(strings).flatten.map(&method(:cleanup_string))
114
115
  end
115
116
 
@@ -120,7 +121,7 @@ module MetaTags
120
121
  # @param [String] natural_separator natural separator to truncate at.
121
122
  # @return [String] truncated string.
122
123
  #
123
- def self.truncate(string, limit = nil, natural_separator = ' ')
124
+ def truncate(string, limit = nil, natural_separator = ' ')
124
125
  string = helpers.truncate(string, length: limit, separator: natural_separator, omission: '', escape: false) if limit
125
126
  string.html_safe
126
127
  end
@@ -133,8 +134,8 @@ module MetaTags
133
134
  # @param [String] natural_separator natural separator to truncate at.
134
135
  # @return [String] truncated string.
135
136
  #
136
- def self.truncate_array(string_array, limit = nil, separator = '', natural_separator = ' ')
137
- return string_array if limit.nil? || limit.zero?
137
+ def truncate_array(string_array, limit = nil, separator = '', natural_separator = ' ')
138
+ return string_array if limit.nil? || limit <= 0
138
139
 
139
140
  length = 0
140
141
  result = []
@@ -157,14 +158,38 @@ module MetaTags
157
158
  result
158
159
  end
159
160
 
160
- def self.calculate_limit_left(limit, length, result, separator)
161
+ private
162
+
163
+ def calculate_limit_left(limit, length, result, separator)
161
164
  limit - length - (result.any? ? separator.length : 0)
162
165
  end
163
166
 
164
- def self.calculate_limit(site_title, separator)
165
- return MetaTags.config.title_limit unless site_title.present?
167
+ def truncate_title(site_title, title, separator)
168
+ if MetaTags.config.title_limit && MetaTags.config.title_limit > 0
169
+ site_title_limited_length, title_limited_length = calculate_title_limits(site_title, title, separator)
170
+
171
+ title = title_limited_length > 0 ? truncate_array(title, title_limited_length, separator) : []
172
+ site_title = site_title_limited_length > 0 ? truncate(site_title, site_title_limited_length) : nil
173
+ end
166
174
 
167
- MetaTags.config.title_limit - separator.length
175
+ [site_title, title]
176
+ end
177
+
178
+ def calculate_title_limits(site_title, title, separator)
179
+ # What should we truncate first: site title or page title?
180
+ main_title = MetaTags.config.truncate_site_title_first ? title : [site_title]
181
+
182
+ main_length = main_title.map(&:length).sum + (main_title.size - 1) * separator.length
183
+ main_limited_length = MetaTags.config.title_limit
184
+
185
+ secondary_limited_length = MetaTags.config.title_limit - (main_length > 0 ? main_length + separator.length : 0)
186
+ secondary_limited_length = [0, secondary_limited_length].max
187
+
188
+ if MetaTags.config.truncate_site_title_first
189
+ [ secondary_limited_length, main_limited_length ]
190
+ else
191
+ [ main_limited_length, secondary_limited_length ]
192
+ end
168
193
  end
169
194
  end
170
195
  end
@@ -1,4 +1,5 @@
1
1
  module MetaTags
2
2
  # Gem version.
3
- VERSION = '2.5.0'
3
+
4
+ VERSION = '2.6.0'
4
5
  end
@@ -160,8 +160,6 @@ module MetaTags
160
160
  # @option default [Hash] :alternate ({}) add alternate link tag.
161
161
  # @option default [String] :prev (nil) add prev link tag;
162
162
  # @option default [String] :next (nil) add next link tag.
163
- # @option default [String] :author (nil) add author link tag;
164
- # @option default [String] :publisher (nil) add publisher link tag.
165
163
  # @option default [String, Integer] :refresh (nil) meta refresh tag;
166
164
  # @option default [Hash] :open_graph ({}) add Open Graph meta tags.
167
165
  # @option default [Hash] :open_search ({}) add Open Search link tag.
@@ -20,11 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_dependency "actionpack", ">= 3.2.0", "< 5.2"
23
+ spec.add_dependency "actionpack", ">= 3.2.0", "< 5.3"
24
24
 
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.5.0"
27
- spec.add_development_dependency "rspec-html-matchers", "~> 0.8.0"
25
+ spec.add_development_dependency "rake", "~> 12.0"
26
+ spec.add_development_dependency "rspec", "~> 3.6.0"
27
+ spec.add_development_dependency "rspec-html-matchers", "~> 0.9.1"
28
28
 
29
29
  spec.cert_chain = ["certs/kpumuk.pem"]
30
30
  spec.signing_key = File.expand_path("~/.ssh/gem-kpumuk.pem") if $PROGRAM_NAME =~ /gem\z/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta-tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Shteflyuk
@@ -12,7 +12,7 @@ cert_chain:
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ8wDQYDVQQDDAZrcHVt
14
14
  dWsxFjAUBgoJkiaJk/IsZAEZFgZrcHVtdWsxFDASBgoJkiaJk/IsZAEZFgRpbmZv
15
- MB4XDTE2MDgyNDAxMDYwOFoXDTE3MDgyNDAxMDYwOFowPzEPMA0GA1UEAwwGa3B1
15
+ MB4XDTE3MDgyNDE2MDUzOVoXDTE4MDgyNDE2MDUzOVowPzEPMA0GA1UEAwwGa3B1
16
16
  bXVrMRYwFAYKCZImiZPyLGQBGRYGa3B1bXVrMRQwEgYKCZImiZPyLGQBGRYEaW5m
17
17
  bzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALw2YroZc+IT+rs8NuPu
18
18
  c13DelrxrpAgPEu1zuRb3l7WaHRNWA4TyS8Z6Aa1G2O+FdUZNMW1n7IwP/QMJ9Mz
@@ -23,14 +23,14 @@ cert_chain:
23
23
  /1sCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFPa4
24
24
  VFc1YOlV1u/7EGTwMCAk8YE9MB0GA1UdEQQWMBSBEmtwdW11a0BrcHVtdWsuaW5m
25
25
  bzAdBgNVHRIEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wDQYJKoZIhvcNAQEFBQAD
26
- ggEBAKOnJYyA5Aq2BPQTSd9uxUzoYL010HsxIz2xFPNRxcI9wvgy6tE7noUD6yu5
27
- k/IXjQOiqMag0zGF3rdEbDFHsvDhos9xZeGUaM3YIfoYg4YF7P7HgRCQFYL7G3va
28
- h++H5FhlqFOF8g4lvYZ80AMNBO/tDfGuIzaJFbv+1mlHc2Szd3t7Mt2kNae92OYJ
29
- x9+w3/LzxW8XariFP1RBseVgHdH9JwbranEqRJ51WwJ0zTGgDnvGxOxigExXEfYE
30
- He5T3dBG5WWdIclQcE+JgohBpQ78TcVs1pFNjFmW9pC/P7Rm2GlYqOPHBQG1/Qx9
31
- ySbbrGHRLVz8DCxQbhKw+mdT5bg=
26
+ ggEBADVN1hwt6ryAPcL8DBB7wM/cYy3oVpYDO1rLGfrdEOgI/Kz+qYbp+6cx9RCY
27
+ DOY6N3GVifGBlFEuyfY3Nubx9mG0FzyBytU7Cb+u+HF3Aw/MnGRoUuY3bzxy3sVE
28
+ t9uyKLaSN0e70mipmWWHhzIZg9sXFfNNt1vLipuw8ZScyoJAa1p5AK4syX6ZAL9G
29
+ g8psHzMWdefrDNJaB8PG8BI2Nb0sIKs8HdACKZo+qDO6b+oi4Wk0nLbRH7qnJcww
30
+ QwaoNrsQi488Dsk54YiNQWVouzfjRqEa4uUxSyKmRfQp7MNILESAOCXM+wZIxanu
31
+ C9c9eUxgNTnHhsR3sK0QCIMwtUI=
32
32
  -----END CERTIFICATE-----
33
- date: 2017-08-23 00:00:00.000000000 Z
33
+ date: 2017-08-24 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: actionpack
@@ -41,7 +41,7 @@ dependencies:
41
41
  version: 3.2.0
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '5.2'
44
+ version: '5.3'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
@@ -51,49 +51,49 @@ dependencies:
51
51
  version: 3.2.0
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.2'
54
+ version: '5.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '12.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '12.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.5.0
75
+ version: 3.6.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.5.0
82
+ version: 3.6.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-html-matchers
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.0
89
+ version: 0.9.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.0
96
+ version: 0.9.1
97
97
  description: Search Engine Optimization (SEO) plugin for Ruby on Rails applications.
98
98
  email:
99
99
  - kpumuk@kpumuk.info
@@ -109,6 +109,8 @@ files:
109
109
  - ".ruby-version"
110
110
  - ".travis.yml"
111
111
  - CHANGELOG.md
112
+ - CODE_OF_CONDUCT.md
113
+ - CONTRIBUTING.md
112
114
  - Gemfile
113
115
  - MIT-LICENSE
114
116
  - README.md
@@ -116,6 +118,8 @@ files:
116
118
  - bin/console
117
119
  - bin/setup
118
120
  - certs/kpumuk.pem
121
+ - lib/generators/meta_tags/install_generator.rb
122
+ - lib/generators/meta_tags/templates/config/initializers/meta_tags.rb
119
123
  - lib/meta-tags.rb
120
124
  - lib/meta_tags.rb
121
125
  - lib/meta_tags/configuration.rb
metadata.gz.sig CHANGED
Binary file