enjoy_cms_goto 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 438862c6733e5ddc8babd9081e17e9f4fb9cce0e
4
+ data.tar.gz: 2220eeb77def05841446df355aa1b75c969ad424
5
+ SHA512:
6
+ metadata.gz: 51aba7f620a6f9e7eaffc27907968277f7c25263dd975e964d7c7eddfd92e1cf6f45ac92b4ffdadebdc7c8885c87a7f9ccfc22d27ce4250b60af50efe5f0a8f8
7
+ data.tar.gz: 49a74babeed3906dfc3b94f94ccc6f7c5bd0cf4de698b31e2b1dc00f6e0cfc2c868ac51b5f9aaff130164f4ec44f2d9046b31eef24ccd1de818819c3c8e1fa63
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enjoy_cms_goto.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # EnjoyCmsGoto
2
+
3
+ URL redirect dispatcher (goto-system) for [enjoy_cms](https://github.com/enjoycreative/enjoy_cms). You will know all about transfers to other sites.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'enjoy_cms_goto'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install enjoy_cms_goto
20
+
21
+ ## Usage
22
+
23
+ Add in config/routes.rb
24
+
25
+ ```ruby
26
+ enjoy_cms_goto_routes
27
+ ```
28
+
29
+ and in config/application.rb
30
+
31
+ ```ruby
32
+ config.middleware.use Enjoy::Goto::Middleware, {excluded_hosts: []}
33
+ ```
34
+
35
+ Also you can specify excluded_hosts. This are hosts you don't want go through this system.
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/enjoycreative/enjoy_cms_goto.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Enjoy::Goto::Decorators
2
+ module Transfers
3
+ extend ActiveSupport::Concern
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Enjoy::Goto
2
+ class TransfersController < ApplicationController
3
+ include Enjoy::Goto::Controllers::Transfers
4
+
5
+ include Enjoy::Goto::Decorators::Transfers
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Enjoy::Goto
2
+ class TransfersController < ApplicationController
3
+ include Enjoy::Goto::Controllers::Transfers
4
+
5
+ include Enjoy::Goto::Decorators::Transfers
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy::Goto::Decorators
2
+ module Transfer
3
+ extend ActiveSupport::Concern
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Enjoy::Goto
2
+ class Transfer
3
+ include Enjoy::Goto::Models::Transfer
4
+
5
+ include Enjoy::Goto::Decorators::Transfer
6
+
7
+ rails_admin(&Enjoy::Goto::Admin::Transfer.config(rails_admin_add_fields) { |config|
8
+ rails_admin_add_config(config)
9
+ })
10
+ end
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "enjoy_cms_goto"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'enjoy/goto/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "enjoy_cms_goto"
8
+ spec.version = Enjoy::Goto::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["dev@enjoycreate.ru"]
11
+
12
+ spec.summary = %q{URL redirect dispatcher with EnjoyCMS support.}
13
+ spec.description = %q{URL redirect dispatcher with EnjoyCMS support.}
14
+ spec.homepage = "https://github.com/enjoycreative/enjoy_cms_goto"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency 'enjoy_cms', "~> 0.3.5"
34
+ spec.add_dependency 'nokogiri'
35
+ spec.add_dependency 'addressable'
36
+ end
@@ -0,0 +1,56 @@
1
+ module Enjoy::Goto
2
+ module Admin
3
+ module Transfer
4
+ def self.config(fields = {})
5
+ Proc.new {
6
+
7
+ field :creator do
8
+ pretty_value do
9
+ unless bindings[:object].creator.blank?
10
+ route = (bindings[:view] || bindings[:controller])
11
+ creator = bindings[:object].creator
12
+ model_name = creator.class.to_param.gsub("::", "~").underscore
13
+ _url = route.rails_admin.show_path(model_name: model_name, id: creator._id)
14
+ route.link_to(creator.name_for_enjoy_cms, _url, class: "creator_link")
15
+ end
16
+ end
17
+ end
18
+ field :created_at
19
+ field :url do
20
+ pretty_value do
21
+ unless bindings[:object].url.blank?
22
+ route = (bindings[:view] || bindings[:controller])
23
+ _target = Addressable::URI.parse(bindings[:object].url).to_s
24
+ route.link_to(_target, _target, title: _target, target: :_blank)
25
+ end
26
+ end
27
+ end
28
+ field :recieved_url
29
+ field :host do
30
+ pretty_value do
31
+ unless bindings[:object].host.blank?
32
+ route = (bindings[:view] || bindings[:controller])
33
+ _target = Addressable::URI.parse(bindings[:object].host).to_s
34
+ route.link_to(_target, _target, title: _target, target: :_blank)
35
+ end
36
+ end
37
+ end
38
+ field :referer do
39
+ pretty_value do
40
+ unless bindings[:object].referer.blank?
41
+ route = (bindings[:view] || bindings[:controller])
42
+ _target = Addressable::URI.parse(bindings[:object].referer).to_s
43
+ route.link_to(_target, _target, title: _target, target: :_blank)
44
+ end
45
+ end
46
+ end
47
+ field :source_ip
48
+
49
+ if block_given?
50
+ yield self
51
+ end
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+ module Enjoy::Goto
2
+ module Admin
3
+ class << self
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ module Enjoy
2
+ module Goto
3
+ def self.configuration
4
+ @configuration ||= Configuration.new
5
+ end
6
+ def self.config
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield configuration
12
+ end
13
+
14
+ class Configuration
15
+
16
+ def initialize
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ module Enjoy::Goto
2
+ module Controllers
3
+ module Transfers
4
+ extend ActiveSupport::Concern
5
+
6
+ def index
7
+ url = Addressable::URI.parse(params[:url]) rescue nil
8
+ referer = (request.referer ? Addressable::URI.parse(request.referer) : nil) rescue nil
9
+
10
+ @transfer = Transfer.new
11
+ @transfer.recieved_url = params[:url]
12
+ @transfer.url = url.to_s
13
+ @transfer.host = url.host.to_s if url
14
+ @transfer.referer = referer.to_s
15
+ @transfer.save
16
+
17
+ redirect_to @transfer.url, code: 303
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module Enjoy
2
+ module Goto
3
+ class Engine < ::Rails::Engine
4
+ # isolate_namespace Enjoy::Goto
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ require 'nokogiri'
2
+ require 'addressable'
3
+ require 'rack'
4
+
5
+ module Enjoy::Goto
6
+ class Middleware
7
+
8
+ def initialize(app, options = {})
9
+ @app = app
10
+ @excluded_hosts = options.delete(:excluded_hosts) || []
11
+ self
12
+ end
13
+
14
+ def call(env)
15
+ status, headers, body = @app.call(env)
16
+
17
+ if headers['Content-Type'].to_s.include?('text/html')
18
+ doc = Nokogiri::HTML.parse(body.body)
19
+ doc.css("a[href]").each do |a|
20
+ _href = a['href']
21
+ if _href =~ /^(https?:)?\/\//i
22
+ begin
23
+ _host = Addressable::URI.parse(_href).host
24
+ puts _href
25
+ puts _host
26
+ unless @excluded_hosts.include?(_host)
27
+ a['href'] = Rails.application.routes.url_helpers.enjoy_goto_path(url: _href)
28
+ end
29
+ rescue
30
+ end
31
+ end
32
+ end
33
+ return [status, headers, [doc.to_html]]
34
+ end
35
+
36
+ [status, headers, body]
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module Enjoy::Goto
2
+ module Models
3
+ module Mongoid
4
+ module Transfer
5
+ extend ActiveSupport::Concern
6
+ include ::Mongoid::Userstamp
7
+
8
+ included do
9
+ field :recieved_url, type: String
10
+ field :url, type: String
11
+ field :host, type: String
12
+ field :referer, type: String
13
+ field :source_ip, type: String
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Enjoy::Goto
2
+ module Models
3
+ module Transfer
4
+ extend ActiveSupport::Concern
5
+ include Enjoy::Model
6
+
7
+ include Enjoy::Goto.orm_specific('Transfer')
8
+
9
+ include ManualSlug
10
+
11
+ included do
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+
4
+ def enjoy_cms_goto_routes
5
+
6
+ scope module: 'enjoy' do
7
+ scope module: 'goto' do
8
+ get '/goto/*url' => 'transfers#index', as: :enjoy_goto, format: false
9
+ end
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Enjoy
2
+ module Goto
3
+ VERSION = "0.3.5"
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ require "enjoy/goto/version"
2
+
3
+ require "enjoy/goto/routes"
4
+
5
+ require 'enjoy_cms'
6
+
7
+ require 'mongoid'
8
+ require 'mongoid_userstamp'
9
+
10
+ require 'enjoy/goto/configuration'
11
+ require 'enjoy/goto/engine'
12
+ require "enjoy/goto/middleware"
13
+
14
+ module Enjoy
15
+ module Goto
16
+ class << self
17
+ def orm
18
+ :mongoid
19
+ end
20
+ def mongoid?
21
+ Enjoy::Goto.orm == :mongoid
22
+ end
23
+ def active_record?
24
+ Enjoy::Goto.orm == :active_record
25
+ end
26
+ def model_namespace
27
+ "Enjoy::Goto::Models::#{Enjoy::Goto.orm.to_s.camelize}"
28
+ end
29
+ def orm_specific(name)
30
+ "#{model_namespace}::#{name}".constantize
31
+ end
32
+ end
33
+
34
+ autoload :Admin, 'enjoy/goto/admin'
35
+ module Admin
36
+ autoload :Transfer, 'enjoy/goto/admin/transfer'
37
+ end
38
+
39
+ module Models
40
+ autoload :Transfer, 'enjoy/goto/models/transfer'
41
+
42
+ module Mongoid
43
+ autoload :Transfer, 'enjoy/goto/models/mongoid/transfer'
44
+ end
45
+ end
46
+
47
+ module Controllers
48
+ autoload :Transfers, 'enjoy/goto/controllers/transfers'
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+
3
+ module Enjoy::Goto::Config
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc 'Enjoy::Goto Config generator'
8
+ def install
9
+ template 'enjoy_goto.erb', "config/initializers/enjoy_goto.rb"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ Enjoy::Goto.configure do |config|
2
+ ##### defaults #####
3
+ end
data/release.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push
6
+ git push gh master
7
+ rake release
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enjoy_cms_goto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.5
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: enjoy_cms
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: URL redirect dispatcher with EnjoyCMS support.
84
+ email:
85
+ - dev@enjoycreate.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - app/controllers/concerns/enjoy/goto/decorators/transfers.rb
97
+ - app/controllers/enjoy/catalog/transfers_controller.rb
98
+ - app/controllers/enjoy/goto/transfers_controller.rb
99
+ - app/models/concerns/enjoy/goto/decorators/transfer.rb
100
+ - app/models/enjoy/goto/transfer.rb
101
+ - bin/console
102
+ - bin/setup
103
+ - config/initializers/rails_admin.rb
104
+ - enjoy_cms_goto.gemspec
105
+ - lib/enjoy/goto/admin.rb
106
+ - lib/enjoy/goto/admin/transfer.rb
107
+ - lib/enjoy/goto/configuration.rb
108
+ - lib/enjoy/goto/controllers/transfers.rb
109
+ - lib/enjoy/goto/engine.rb
110
+ - lib/enjoy/goto/middleware.rb
111
+ - lib/enjoy/goto/models/mongoid/transfer.rb
112
+ - lib/enjoy/goto/models/transfer.rb
113
+ - lib/enjoy/goto/routes.rb
114
+ - lib/enjoy/goto/version.rb
115
+ - lib/enjoy_cms_goto.rb
116
+ - lib/generators/config/install_generator.rb
117
+ - lib/generators/config/templates/enjoy_goto.erb
118
+ - release.sh
119
+ homepage: https://github.com/enjoycreative/enjoy_cms_goto
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.8
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: URL redirect dispatcher with EnjoyCMS support.
143
+ test_files: []