metanol 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,87 +1,100 @@
1
- module Metanol::Meta
1
+ # frozen_string_literal: true
2
2
 
3
- class Base
4
- attr_writer :value
3
+ module Metanol
4
+ module Meta
5
+ class Base
6
+ ERR_FILTERS_WRONG_TYPE = 'The <filters> parameter must be an Array.'
7
+ ERR_FILTERS_WRONG_VALUE_TYPE =
8
+ 'The <filters> parameter must include only string or symbol values.'
9
+ SUPPORTED_FILTERS = %i[html overspaces whitespaces clean].freeze
5
10
 
6
- SUPPORTED_FILTERS = [:html, :overspaces, :whitespaces, :clean]
11
+ attr_writer :value
12
+ attr_reader :name
7
13
 
8
- def initialize(name, value, filters=[])
9
- raise NameError.new "The meta tag '#{name}' isn't supported.", name unless valid?(name)
10
- @name = name
11
- @value = value
12
- self.filters = filters
13
- end
14
+ def initialize(name, value, filters = [])
15
+ @name = name.to_sym
16
+ raise(NameError.new("The meta tag '#{@name}' isn't supported.", @name)) unless valid?(@name)
14
17
 
15
- def filters=(value)
16
- @filters = validate_filters(value)
17
- end
18
+ @value = value
19
+ self.filters = filters
20
+ end
18
21
 
19
- def render
20
- result = self.value
21
- !result.blank? ? "<meta #{self.attr_name}=\"#{self.name}\" #{self.attr_value}=\"#{result}\" />" : ''
22
- end
22
+ def filters=(value)
23
+ @filters = validate_filters(value)
24
+ end
23
25
 
24
- def name
25
- @name
26
- end
26
+ def render
27
+ result = value
28
+ return '' if result.blank?
27
29
 
28
- def value
29
- result = @value
30
- return result unless filters?
31
- result = self.class.filter_html(result) if @filters.include?(:html) || @filters.include?(:clean)
32
- result = self.class.filter_whitespaces(result) if @filters.include?(:whitespaces) || @filters.include?(:clean)
33
- result = self.class.filter_overspaces(result) if @filters.include?(:overspaces) || @filters.include?(:clean)
34
- result
35
- end
30
+ "<meta #{attr_name}=\"#{name}\" #{attr_value}=\"#{result}\" />"
31
+ end
36
32
 
37
- def self.filter_html(text)
38
- text = text.gsub(/\<br\/?\>/, ' ')
39
- text.gsub(/\<\/?\w+\/?\>/, '')
40
- end
33
+ def value
34
+ result = @value
35
+ return result if @filters.blank?
41
36
 
42
- def self.filter_overspaces(text)
43
- text.gsub(/[\ ]{2,}/, ' ')
44
- end
37
+ filter_overspaces(filter_whitespaces(filter_html_tags(result)))
38
+ end
45
39
 
46
- def self.filter_whitespaces(text)
47
- text.gsub(/\s/, ' ')
48
- end
40
+ def self.filter_html(text)
41
+ text = text.gsub(%r{<br/?>}, ' ')
42
+ text.gsub(%r{</?\w+/?>}, '')
43
+ end
49
44
 
50
- protected
45
+ def self.filter_overspaces(text)
46
+ text.gsub(/\ {2,}/, ' ')
47
+ end
51
48
 
52
- def valid?(name)
53
- true
54
- end
49
+ def self.filter_whitespaces(text)
50
+ text.gsub(/\s/, ' ')
51
+ end
55
52
 
56
- def filters?
57
- @filters && !@filters.empty?
58
- end
53
+ private
59
54
 
60
- def attr_name
61
- 'name'
62
- end
55
+ def valid?(_name)
56
+ true
57
+ end
63
58
 
64
- def attr_value
65
- 'content'
66
- end
59
+ def attr_name
60
+ 'name'
61
+ end
67
62
 
68
- private
63
+ def attr_value
64
+ 'content'
65
+ end
69
66
 
70
- def validate_filters(filters=[])
71
- result = []
72
- raise StandardError.new("The filters parameter must be an Array.") unless filters.is_a?(Array)
73
- begin
74
- filters.each do |filter|
75
- filter_value = filter.to_sym
76
- StandardError.new("Only #{SUPPORTED_FILTERS.join(', ')} filters are supported.") unless SUPPORTED_FILTERS.include? filter_value
77
- result << filter_value
67
+ def validate_filters(filters = [])
68
+ result = []
69
+ raise StandardError, ERR_FILTERS_WRONG_TYPE unless filters.is_a?(Array)
70
+
71
+ begin
72
+ filters.map(&:to_sym).each do |filter_value|
73
+ result << validate_filter(filter_value)
74
+ end
75
+ rescue NoMethodError
76
+ raise StandardError, ERR_FILTERS_WRONG_VALUE_TYPE
78
77
  end
79
- rescue NoMethodError
80
- raise StandardError.new("The filters parameter must includes only string or symbol values.")
78
+ result
81
79
  end
82
- result
83
- end
84
80
 
85
- end
81
+ def validate_filter(filter_value)
82
+ return filter_value if SUPPORTED_FILTERS.include? filter_value
86
83
 
87
- end
84
+ raise(StandardError, "Only #{SUPPORTED_FILTERS.join(', ')} filters are supported.")
85
+ end
86
+
87
+ def filter_html_tags(result)
88
+ (@filters & %i[html clean]).presence ? self.class.filter_html(result) : result
89
+ end
90
+
91
+ def filter_whitespaces(result)
92
+ (@filters & %i[whitespaces clean]).presence ? self.class.filter_whitespaces(result) : result
93
+ end
94
+
95
+ def filter_overspaces(result)
96
+ (@filters & %i[overspaces clean]).presence ? self.class.filter_overspaces(result) : result
97
+ end
98
+ end
99
+ end
100
+ end
@@ -1,11 +1,13 @@
1
- module Metanol::Meta
1
+ # frozen_string_literal: true
2
2
 
3
- class Main < Base
4
- def render
5
- result = self.value
6
- return (!result.blank? ? "<title>#{result}</title>": '') if @name == :title
7
- super
3
+ module Metanol
4
+ module Meta
5
+ class Main < Base
6
+ def render
7
+ return (value.present? ? "<title>#{value}</title>" : '') if @name == :title
8
+
9
+ super
10
+ end
8
11
  end
9
12
  end
10
-
11
- end
13
+ end
@@ -1,13 +1,13 @@
1
- module Metanol::Meta
1
+ # frozen_string_literal: true
2
2
 
3
- class MicroData < Base
3
+ module Metanol
4
+ module Meta
5
+ class MicroData < Base
6
+ protected
4
7
 
5
- protected
6
-
7
- def attr_name
8
- 'itemprop'
8
+ def attr_name
9
+ 'itemprop'
10
+ end
9
11
  end
10
-
11
12
  end
12
-
13
- end
13
+ end
@@ -1,21 +1,23 @@
1
- module Metanol::Meta
1
+ # frozen_string_literal: true
2
2
 
3
- class OpenGraph < Base
3
+ module Metanol
4
+ module Meta
5
+ class OpenGraph < Base
6
+ def self.render_current_url(url)
7
+ return '' if url.blank?
4
8
 
5
- def self.render_current_url(url)
6
- !url.blank? ? "<meta property=\"og:url\" content=\"#{url}\" />" : ''
7
- end
9
+ "<meta property=\"og:url\" content=\"#{url}\" />"
10
+ end
8
11
 
9
- def name
10
- "og:#{@name}"
11
- end
12
+ def name
13
+ "og:#{@name}"
14
+ end
12
15
 
13
- protected
16
+ protected
14
17
 
15
- def attr_name
16
- 'property'
18
+ def attr_name
19
+ 'property'
20
+ end
17
21
  end
18
-
19
22
  end
20
-
21
- end
23
+ end
@@ -1,22 +1,24 @@
1
- module Metanol::Meta
2
- class Webmaster < Base
1
+ # frozen_string_literal: true
3
2
 
4
- SUPPORT_TAGS = {
5
- yandex: 'yandex-verification',
6
- google: 'google-site-verification',
3
+ module Metanol
4
+ module Meta
5
+ class Webmaster < Base
6
+ SUPPORT_TAGS = {
7
7
  bing: 'msvalidate.01',
8
- alexa: 'alexaVerifyID'
9
- }
8
+ alexa: 'alexaVerifyID',
9
+ yandex: 'yandex-verification',
10
+ google: 'google-site-verification'
11
+ }.freeze
10
12
 
11
- def name
12
- SUPPORT_TAGS[@name]
13
- end
13
+ def name
14
+ SUPPORT_TAGS[@name]
15
+ end
14
16
 
15
- protected
17
+ protected
16
18
 
17
- def valid?(name)
18
- !SUPPORT_TAGS[name.to_sym].nil?
19
+ def valid?(name)
20
+ SUPPORT_TAGS[name].present?
21
+ end
19
22
  end
20
-
21
23
  end
22
- end
24
+ end
@@ -1,8 +1,8 @@
1
1
  module Metanol
2
- class Railtie < ::Rails::Railtie #:nodoc:
3
- initializer 'metanolize' do |app|
4
- ::ActionView::Base.send :include, Metanol::Helpers
5
- ::ActionController::Base.send :include, Metanol::EngineController
2
+ class Railtie < ::Rails::Railtie # :nodoc:
3
+ initializer 'metanolize' do |_app|
4
+ ::ActionView::Base.include Metanol::Helpers
5
+ ::ActionController::Base.include Metanol::EngineController
6
6
  end
7
7
  end
8
- end
8
+ end
@@ -1,8 +1,8 @@
1
1
  module Metanol
2
2
  SUPPORT_GROUPS = {
3
- main: Meta::Main,
4
- og: Meta::OpenGraph,
5
- wm: Meta::Webmaster,
6
- md: Meta::MicroData
7
- }
3
+ main: Meta::Main,
4
+ og: Meta::OpenGraph,
5
+ wm: Meta::Webmaster,
6
+ md: Meta::MicroData
7
+ }.freeze
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Metanol
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'.freeze
3
3
  end
data/metanol.gemspec CHANGED
@@ -1,26 +1,44 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'metanol/version'
5
6
 
6
- Gem::Specification.new do |gem|
7
- gem.name = 'metanol'
8
- gem.version = Metanol::VERSION
9
- gem.platform = Gem::Platform::RUBY
10
- gem.authors = ['Eugene Kondratyuk']
11
- gem.email = ['ekondr@gmail.com']
12
- gem.description = %q{This is a meta tags plugin which helps to manage meta tags in your Rails application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as Google, Bing, Yandex, Alexa verification meta tags), MicroData meta tags and other standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications.}
13
- gem.summary = %q{A <META> tags engine plugin for Rails 3.2+ applications}
14
- gem.homepage = 'https://github.com/ekondr/metanol'
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'metanol'
9
+ spec.version = Metanol::VERSION
10
+ spec.authors = ['Yevhen Kondratiuk']
11
+ spec.email = ['ekondr@gmail.com']
15
12
 
16
- gem.rubyforge_project = 'metanol'
13
+ spec.summary = '<META> tags engine plugin for Ruby on Rails applications'
14
+ spec.description = 'This is a meta tags plugin which helps to manage meta tags in '\
15
+ 'your Rails application. It supports some OpenGraph meta tags, '\
16
+ "Webmaster's meta tags (such as Google, Bing, Yandex, Alexa "\
17
+ 'verification tags), MicroData meta tags and other standard '\
18
+ 'HTML meta tags (such as a <description>, <title> etc). It can be used by '\
19
+ 'Rails 3.2+ applications.'
20
+ spec.homepage = 'https://github.com/ekondr/metanol'
21
+ spec.license = 'MIT'
17
22
 
18
- gem.files = `git ls-files`.split($/)
19
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
- gem.require_paths = ['lib']
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
25
+ spec.respond_to?(:metadata) ||
26
+ raise('RubyGems 2.0 or newer is required to protect against public gem pushes.')
22
27
 
23
- gem.licenses = ['MIT']
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = 'bin'
34
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+ spec.required_ruby_version = '>= 2.3'
24
37
 
25
- gem.add_dependency 'rails', '>= 3.2'
38
+ spec.add_dependency 'rails', '>= 6.0'
39
+ spec.add_development_dependency 'capybara', '>= 0'
40
+ spec.add_development_dependency 'pry-byebug'
41
+ spec.add_development_dependency 'rspec', '>= 3.0'
42
+ spec.add_development_dependency 'rspec-rails', '>= 5.0'
43
+ spec.add_development_dependency 'sqlite3', '>= 0'
26
44
  end
metadata CHANGED
@@ -1,42 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
- - Eugene Kondratyuk
8
- autorequire:
7
+ - Yevhen Kondratiuk
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.2'
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '5.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: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
27
97
  description: This is a meta tags plugin which helps to manage meta tags in your Rails
28
98
  application. It supports some OpenGraph meta tags, Webmaster's meta tags (such as
29
- Google, Bing, Yandex, Alexa verification meta tags), MicroData meta tags and other
30
- standard HTML meta tags (such as a description). It can be used by Rails 3.2+ applications.
99
+ Google, Bing, Yandex, Alexa verification tags), MicroData meta tags and other standard
100
+ HTML meta tags (such as a <description>, <title> etc). It can be used by Rails 3.2+
101
+ applications.
31
102
  email:
32
103
  - ekondr@gmail.com
33
104
  executables: []
34
105
  extensions: []
35
106
  extra_rdoc_files: []
36
107
  files:
37
- - .gitignore
38
- - .rspec
108
+ - ".gitignore"
109
+ - ".overcommit.yml"
110
+ - ".overcommit_gems"
111
+ - ".overcommit_gems.lock"
112
+ - ".rspec"
113
+ - ".rubocop.yml"
114
+ - ".rubocop_todo.yml"
39
115
  - Gemfile
116
+ - Gemfile.lock
40
117
  - LICENSE.txt
41
118
  - README.md
42
119
  - Rakefile
@@ -53,36 +130,27 @@ files:
53
130
  - lib/metanol/support.rb
54
131
  - lib/metanol/version.rb
55
132
  - metanol.gemspec
56
- - spec/controllers/home_controller_spec.rb
57
- - spec/controllers/tests_controller_spec.rb
58
- - spec/spec_helper.rb
59
- - spec/support/application.rb
60
133
  homepage: https://github.com/ekondr/metanol
61
134
  licenses:
62
135
  - MIT
63
136
  metadata: {}
64
- post_install_message:
137
+ post_install_message:
65
138
  rdoc_options: []
66
139
  require_paths:
67
140
  - lib
68
141
  required_ruby_version: !ruby/object:Gem::Requirement
69
142
  requirements:
70
- - - '>='
143
+ - - ">="
71
144
  - !ruby/object:Gem::Version
72
- version: '0'
145
+ version: '2.3'
73
146
  required_rubygems_version: !ruby/object:Gem::Requirement
74
147
  requirements:
75
- - - '>='
148
+ - - ">="
76
149
  - !ruby/object:Gem::Version
77
150
  version: '0'
78
151
  requirements: []
79
- rubyforge_project: metanol
80
- rubygems_version: 2.2.2
81
- signing_key:
152
+ rubygems_version: 3.1.2
153
+ signing_key:
82
154
  specification_version: 4
83
- summary: A <META> tags engine plugin for Rails 3.2+ applications
84
- test_files:
85
- - spec/controllers/home_controller_spec.rb
86
- - spec/controllers/tests_controller_spec.rb
87
- - spec/spec_helper.rb
88
- - spec/support/application.rb
155
+ summary: "<META> tags engine plugin for Ruby on Rails applications"
156
+ test_files: []
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe HomeController do
4
- context 'render meta tags with some global ones' do
5
-
6
- context 'all meta tags' do
7
- before { get :index }
8
-
9
- it { response.should have_selector("meta[content=\"#{url_for(controller: :home, action: :index, host: 'test.host')}\"]", property: 'og:url') }
10
- it { response.should have_selector('meta[content="OpenGraph Title"]', property: 'og:title') }
11
- it { response.should have_selector('meta[content="OpenGraph Description"]', property: 'og:description') }
12
- it { response.should have_selector('meta[content="website"]', property: 'og:type') }
13
- it { response.should have_selector('meta[content="uk_UA"]', property: 'og:locale') }
14
- it { response.should have_selector('meta[content="bing code"]', name: 'msvalidate.01') }
15
- it { response.should have_selector('meta[content="alexa code"]', name: 'alexaVerifyID') }
16
- it { response.should have_selector('meta[content="google code"]', name: 'google-site-verification') }
17
- it { response.should have_selector('meta[content="yandex code"]', name: 'yandex-verification') }
18
- it { response.body.should =~ /<title>Index Page<\/title>/ }
19
- end
20
-
21
- context "only WebMaster's meta tags" do
22
- before { get :new }
23
-
24
- it { response.should_not have_selector('meta[content="website"]', property: 'og:type') }
25
- it { response.should_not have_selector('meta[content="uk_UA"]', property: 'og:locale') }
26
- it { response.should have_selector('meta[content="bing code"]', name: 'msvalidate.01') }
27
- it { response.should have_selector('meta[content="alexa code"]', name: 'alexaVerifyID') }
28
- it { response.should have_selector('meta[content="google code"]', name: 'google-site-verification') }
29
- it { response.should have_selector('meta[content="yandex code"]', name: 'yandex-verification') }
30
- end
31
-
32
- context 'correct title tag' do
33
- before { get :index }
34
- before { get :get_title }
35
- it { response.body.should_not =~ /<title>Index Page<\/title>/ }
36
- end
37
-
38
- end
39
- end