enjoy_cms_goto 0.3.7 → 0.4.0.beta3

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: ac37e01d38bd2f30b7a1386733bac3989a21ad05
4
- data.tar.gz: 960fd4f624f441a30aec6a2c8a3b60579c4aa6a2
3
+ metadata.gz: e44d5d1040026ba29bc6070702d9f7ca05fffe8b
4
+ data.tar.gz: bc002af3019a8c6f5490d587877e06830516e22f
5
5
  SHA512:
6
- metadata.gz: 2f718d039cdd527dcc7f1844182720aae509313c640f37ef33254bea3aa254b4ef21c2df3a5b21b7eb7e73ad5e48a7700e828c93b0012e001f670a54ded14c09
7
- data.tar.gz: 3582d133bdb0f82f9f5ae338881338e51cd8b6a34fdb49592aff673dc402347553ad52d7d725f6b2b7215deb3afb43be9138b4d807e500491dbb59191e710c4a
6
+ metadata.gz: f4b36e4fda1839ccc6f8d9e541cb40f1da45d46baf1a903114703fa00a74e439716380f6df371bd1755c434afdc19b5db8e63c0bff47a55fdd8fcdfc07f64306
7
+ data.tar.gz: 2bc15d2253430224d927468da1025dc079847b3d34933c68b9b8d3afbd76817077d963ba7c2931789e5c6cbbfbe162b29dd96563d98f500df564133ea1d9eca7
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ enjoy_cms_goto
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,22 @@
1
+ Enjoy.configure do |config|
2
+ config.ability_manager_config ||= []
3
+ config.ability_manager_config << {
4
+ method: :can,
5
+ model: Enjoy::Goto::Transfer,
6
+ actions: [:read]
7
+ }
8
+
9
+ config.ability_admin_config ||= []
10
+ config.ability_admin_config << {
11
+ method: :can,
12
+ model: Enjoy::Goto::Transfer,
13
+ actions: :manage
14
+ }
15
+ end
16
+
17
+ Enjoy.rails_admin_configure do |config|
18
+ if defined?(RailsAdminComments)
19
+ config.action_visible_for :comments, 'Enjoy::Goto::Transfer'
20
+ config.action_visible_for :model_comments, 'Enjoy::Goto::Transfer'
21
+ end
22
+ end
@@ -1,5 +1,7 @@
1
1
  ru:
2
- mongoid:
2
+ enjoy:
3
+ goto: 'Переходы с сайта'
4
+ mongoid: &mongoid
3
5
  models:
4
6
  enjoy/goto/transfer: "Переходы с сайта"
5
7
  attributes:
@@ -10,3 +12,6 @@ ru:
10
12
  referer: Страница, с которой перешли
11
13
  source_ip: IP пользователя
12
14
  creator: Пользователь
15
+
16
+ activerecord:
17
+ <<: *mongoid
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.10"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
 
33
- spec.add_dependency 'enjoy_cms', "~> 0.3.7"
33
+ spec.add_dependency 'enjoy_cms', "~> 0.4.0.beta3"
34
34
  spec.add_dependency 'nokogiri'
35
35
  spec.add_dependency 'addressable'
36
36
  end
@@ -3,6 +3,11 @@ module Enjoy::Goto
3
3
  module Transfer
4
4
  def self.config(fields = {})
5
5
  Proc.new {
6
+ if defined?(Enjoy::Feedback)
7
+ navigation_label I18n.t('enjoy.feedback')
8
+ else
9
+ navigation_label I18n.t('enjoy.goto')
10
+ end
6
11
 
7
12
  field :creator do
8
13
  filterable true
@@ -13,7 +13,26 @@ module Enjoy
13
13
 
14
14
  class Configuration
15
15
 
16
+ attr_accessor :css_selector
17
+ attr_accessor :href_regex
18
+ attr_accessor :excluded_hosts
19
+
20
+ attr_accessor :add_nofollow
21
+ attr_accessor :add_noindex
22
+ attr_accessor :add_noreferrer
23
+ attr_accessor :add_noopener
24
+ attr_accessor :del_attrs
25
+
16
26
  def initialize
27
+ @css_selector = "a[href]"
28
+ @href_regex = /^(https?:)?\/\//i
29
+ @excluded_hosts = []
30
+
31
+ @add_nofollow = true
32
+ @add_noindex = true
33
+ @add_noreferrer = true
34
+ @add_noopener = true
35
+ @del_attrs = true
17
36
  end
18
37
  end
19
38
  end
@@ -4,10 +4,10 @@ module Enjoy::Goto
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  def index
7
- url = Addressable::URI.parse(params[:url]) rescue nil
7
+ url = Addressable::URI.heuristic_parse(params[:url]) rescue nil
8
8
  referer = (request.referer ? Addressable::URI.parse(request.referer) : nil) rescue nil
9
9
 
10
- @transfer = Transfer.new
10
+ @transfer = transfer_class.new
11
11
  @transfer.recieved_url = params[:url]
12
12
  @transfer.url = url.to_s
13
13
  @transfer.host = url.host.to_s if url
@@ -18,6 +18,10 @@ module Enjoy::Goto
18
18
  redirect_to @transfer.url, code: 303
19
19
  end
20
20
 
21
+ def transfer_class
22
+ Enjoy::Goto::Transfer
23
+ end
24
+
21
25
  end
22
26
  end
23
27
  end
@@ -5,9 +5,20 @@ require 'rack'
5
5
  module Enjoy::Goto
6
6
  class Middleware
7
7
 
8
+ ATTRS = {
9
+ disabled: 'data-enjoy-goto-disabled',
10
+ add_nofollow: 'data-enjoy-goto-add-nofollow',
11
+ add_noindex: 'data-enjoy-goto-add-noindex',
12
+ add_noreferrer: 'data-enjoy-goto-add-noreferrer',
13
+ add_noopener: 'data-enjoy-goto-add-noopener',
14
+ del_attrs: 'data-enjoy-goto-del-attrs'
15
+ }
16
+
17
+ REL_ATTRS = ATTRS
18
+ REL_ATTRS.delete(:disabled)
19
+
8
20
  def initialize(app, options = {})
9
21
  @app = app
10
- @excluded_hosts = options.delete(:excluded_hosts) || []
11
22
  self
12
23
  end
13
24
 
@@ -16,15 +27,22 @@ module Enjoy::Goto
16
27
 
17
28
  if headers['Content-Type'].to_s.include?('text/html')
18
29
  begin
19
- doc = Nokogiri::HTML.parse(body.body)
20
- doc.css("a[href]").each do |a|
30
+ doc = Nokogiri::HTML.fragment(body.body)
31
+ doc.css(Enjoy::Goto.config[:css_selector]).each do |a|
32
+ if (!a[ATTRS[:disabled]].blank? and !["0", "false", "no"].include?(a[ATTRS[:disabled]]))
33
+ del_attrs(a)
34
+ next
35
+ end
36
+
21
37
  _href = a['href']
22
- if _href =~ /^(https?:)?\/\//i
38
+ if _href =~ Enjoy::Goto.config[:href_regex]
23
39
  begin
24
40
  _host = Addressable::URI.parse(_href).host
25
- unless @excluded_hosts.include?(_host)
41
+ unless Enjoy::Goto.config[:excluded_hosts].include?(_host)
26
42
  a['href'] = Rails.application.routes.url_helpers.enjoy_goto_path(url: _href)
27
43
  a['target'] = '_blank' if a['target'].blank?
44
+ set_rel_attribute(a)
45
+ del_attrs(a)
28
46
  end
29
47
  rescue
30
48
  end
@@ -37,5 +55,47 @@ module Enjoy::Goto
37
55
 
38
56
  [status, headers, body]
39
57
  end
58
+
59
+ private
60
+ def check_attr(a, attr_name)
61
+ Enjoy::Goto.config[attr_name] or (!a[ATTRS[attr_name]].blank? and !["0", "false", "no"].include?(a[ATTRS[attr_name]]))
62
+ end
63
+
64
+ def add_attr(a, attr_name)
65
+ rel = a['rel'].blank? ? [] : a.rel.split(" ")
66
+ rel << attr_name unless rel.include?(attr_name)
67
+ a
68
+ end
69
+
70
+ def add_nofollow(a)
71
+ add_attr('nofollow') if check_attr(a, :add_nofollow)
72
+ end
73
+
74
+ def add_noindex(a)
75
+ add_attr('noindex') if check_attr(a, :add_noindex)
76
+ end
77
+
78
+ def add_noreferrer(a)
79
+ add_attr('noreferrer') if check_attr(a, :add_noreferrer)
80
+ end
81
+
82
+ def add_noopener(a)
83
+ add_attr('noopener') if check_attr(a, :add_noopener)
84
+ end
85
+
86
+ def del_attrs(a)
87
+ if check_attr(ATTRS[del_attrs])
88
+ ATTRS.values.each do |attr|
89
+ a.remove_attribute(attr)
90
+ end
91
+ end
92
+ end
93
+
94
+ def set_rel_attribute(a)
95
+ REL_ATTRS.keys.each do |meth|
96
+ self.send(meth, a)
97
+ end
98
+ end
99
+
40
100
  end
41
101
  end
@@ -1,5 +1,5 @@
1
1
  module Enjoy
2
2
  module Goto
3
- VERSION = "0.3.7"
3
+ VERSION = "0.4.0.beta3"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require "enjoy/goto/version"
2
2
 
3
3
  require "enjoy/goto/routes"
4
4
 
5
- require 'enjoy_cms'
5
+ # require 'enjoy_cms'
6
6
 
7
7
  require 'mongoid'
8
8
  require 'mongoid_userstamp'
@@ -15,7 +15,7 @@ module Enjoy
15
15
  module Goto
16
16
  class << self
17
17
  def orm
18
- :mongoid
18
+ :mongoid #Enjoy.orm
19
19
  end
20
20
  def mongoid?
21
21
  Enjoy::Goto.orm == :mongoid
@@ -1,11 +1,11 @@
1
1
  require 'rails/generators'
2
2
 
3
- module Enjoy::Goto::Config
4
- class InstallGenerator < Rails::Generators::Base
3
+ module Enjoy::Goto
4
+ class ConfigGenerator < Rails::Generators::Base
5
5
  source_root File.expand_path('../templates', __FILE__)
6
6
 
7
7
  desc 'Enjoy::Goto Config generator'
8
- def install
8
+ def config
9
9
  template 'enjoy_goto.erb', "config/initializers/enjoy_goto.rb"
10
10
  end
11
11
 
@@ -0,0 +1,12 @@
1
+ Enjoy::Goto.configure do |config|
2
+ ##### defaults #####
3
+ # config.css_selector = "a[href]"
4
+ # config.href_regex = /^(https?:)?\/\//i
5
+ # config.excluded_hosts = []
6
+
7
+ # config.add_nofollow = true
8
+ # config.add_noindex = true
9
+ # config.add_noreferrer = true
10
+ # config.add_noopener = true
11
+ # config.del_attrs = true
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enjoy_cms_goto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kiseliev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.7
47
+ version: 0.4.0.beta3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.7
54
+ version: 0.4.0.beta3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +88,8 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".ruby-gemset"
92
+ - ".ruby-version"
91
93
  - ".travis.yml"
92
94
  - Gemfile
93
95
  - LICENSE.txt
@@ -99,7 +101,7 @@ files:
99
101
  - app/models/enjoy/goto/transfer.rb
100
102
  - bin/console
101
103
  - bin/setup
102
- - config/initializers/rails_admin.rb
104
+ - config/initializers/enjoy_goto.rb
103
105
  - config/locales/enjoy.goto.ru.yml
104
106
  - enjoy_cms_goto.gemspec
105
107
  - lib/enjoy/goto/admin.rb
@@ -113,8 +115,8 @@ files:
113
115
  - lib/enjoy/goto/routes.rb
114
116
  - lib/enjoy/goto/version.rb
115
117
  - lib/enjoy_cms_goto.rb
116
- - lib/generators/config/install_generator.rb
117
- - lib/generators/config/templates/enjoy_goto.erb
118
+ - lib/generators/enjoy/goto/config/install_generator.rb
119
+ - lib/generators/enjoy/goto/config/templates/enjoy_goto.erb
118
120
  - release.sh
119
121
  homepage: https://github.com/enjoycreative/enjoy_cms_goto
120
122
  licenses:
@@ -131,12 +133,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
133
  version: '0'
132
134
  required_rubygems_version: !ruby/object:Gem::Requirement
133
135
  requirements:
134
- - - ">="
136
+ - - ">"
135
137
  - !ruby/object:Gem::Version
136
- version: '0'
138
+ version: 1.3.1
137
139
  requirements: []
138
140
  rubyforge_project:
139
- rubygems_version: 2.4.8
141
+ rubygems_version: 2.5.1
140
142
  signing_key:
141
143
  specification_version: 4
142
144
  summary: URL redirect dispatcher with EnjoyCMS support.
@@ -1,8 +0,0 @@
1
- if defined?(RailsAdmin)
2
- RailsAdmin.config do |config|
3
- config.excluded_models ||= []
4
- config.excluded_models << [
5
- ]
6
- config.excluded_models.flatten!
7
- end
8
- end
@@ -1,3 +0,0 @@
1
- Enjoy::Goto.configure do |config|
2
- ##### defaults #####
3
- end