blueberry_redirector 0.1.0

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: 5086ce1dbfdd05e4cd6982e93d8a994067de3701
4
+ data.tar.gz: 1780e4c0a0e5b1546c1d9b9ed2d6968ca549d4bc
5
+ SHA512:
6
+ metadata.gz: a1fa7fd5076920d4b135e4c7e3944d434637f9d0baecba62d91d55c9581128f8e9902da85e71e0ce6409925b085a647fb52574445d4049d7ecd4deadb50033ce
7
+ data.tar.gz: ac2810c441987b4c4ca083b30633daff223afb7b6045a05a0cb971db696b5fd84befefd29b6c45a48514dce9228ed3f62e8fe2e8bbf116a28f7904fb63c2d2de
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Tonda Pleskac
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.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # BlueberryRedirector
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ 1. Add this to your Gemfile and then `bundle install`:
9
+
10
+ ```ruby
11
+ gem 'blueberry_redirector'
12
+ ```
13
+
14
+ 2. `$ rake redirector:install:migrations`
15
+ 3. `$ rake db:migrate`
16
+
17
+
18
+ ## Contributing
19
+ Contribution directions go here.
20
+
21
+ ## License
22
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
23
+
24
+
25
+ rake blueberry_redirector:install:migrations
data/Rakefile ADDED
@@ -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 = 'BlueberryRedirector'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+ load 'rails/tasks/statistics.rake'
19
+
20
+
21
+
22
+ require 'bundler/gem_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,8 @@
1
+ module BlueberryRedirector
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+
5
+ layout 'blueberry_redirector/application'
6
+ helper BlueberryRedirector::RedirectorHelper
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+ module BlueberryRedirector
2
+ class RedirectorRulesController < ApplicationController
3
+ before_action :find_redirector_rule, only: [:edit, :update, :destroy]
4
+
5
+ def index
6
+ @redirector_rules = RedirectorRule.all
7
+ end
8
+
9
+ def new
10
+ @redirector_rule = RedirectorRule.new
11
+ end
12
+
13
+ def create
14
+ @redirector_rule = RedirectorRule.new redirector_rule_params
15
+ if @redirector_rule.save
16
+ redirect_to redirector_rules_path, notice: t('.success')
17
+ else
18
+ render :new
19
+ end
20
+ end
21
+
22
+ def edit
23
+ end
24
+
25
+ def update
26
+ if @redirector_rule.update_attributes redirector_rule_params
27
+ redirect_to redirector_rules_path, notice: t('.success')
28
+ else
29
+ render :edit
30
+ end
31
+ end
32
+
33
+ def destroy
34
+ @redirector_rule.destroy
35
+ redirect_to redirector_rules_path, notice: t('.success')
36
+ end
37
+
38
+ private
39
+
40
+ def find_redirector_rule
41
+ @redirector_rule = RedirectorRule.find params[:id]
42
+ end
43
+
44
+ def redirector_rule_params
45
+ params.require(:redirector_rule)
46
+ .permit(:source, :destination, :active)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,22 @@
1
+ module BlueberryRedirector
2
+ class RedirectorRulesImportsController < RedirectorRulesController
3
+ def new
4
+ render :new_import
5
+ end
6
+
7
+ def create
8
+ ImportRedirectRules.run redirector_rule_params
9
+ redirect_to redirector_rules_path, notice: t('.success')
10
+
11
+ rescue ImportRedirectRules::ValidationError
12
+ flash[:notice] = t('.wrong_format')
13
+ render :new_import
14
+ end
15
+
16
+ private
17
+
18
+ def redirector_rule_params
19
+ params.require(:redirector_rule)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module BlueberryRedirector
2
+ module RedirectorHelper
3
+ def glyph_bool(bool)
4
+ bool ? 'glyphicon-ok' : 'glyphicon-remove'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ class RedirectorRule < RedirectRule
2
+ end
@@ -0,0 +1,33 @@
1
+ class ImportRedirectRules < Service
2
+ attribute :file
3
+ validates :file, presence: true
4
+
5
+ validate :validate_file_name
6
+
7
+ def execute
8
+ spreadsheet = Roo::Excelx.new(file.path)
9
+ spreadsheet.each_row_streaming do |row|
10
+ source = row[0].value
11
+ destination = row[1].value
12
+
13
+ rule = RedirectorRule.where(source: path(source)).first_or_initialize
14
+ rule.update_attributes(destination: destination, active: true)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def path(path)
21
+ if path
22
+ if !path.start_with?('/')
23
+ '/' + path
24
+ else
25
+ path
26
+ end
27
+ end
28
+ end
29
+
30
+ def validate_file_name
31
+ errors.add(:file, :invalid) unless file.try(:path) =~ /xlsx?\z/
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ class Service
2
+ include ActiveModel::Model
3
+ include Virtus.model
4
+
5
+ ValidationError = Class.new(StandardError)
6
+
7
+ def self.run(params = {})
8
+ new(params).run
9
+ end
10
+
11
+ def execute
12
+ raise NotImplementedError
13
+ end
14
+
15
+ def run
16
+ raise ValidationError unless valid?
17
+ execute
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ tr
2
+ td colspan=4 = t '.no_redirector_rules'
@@ -0,0 +1,6 @@
1
+ h3 = t '.main'
2
+ .body
3
+ .row
4
+ .col-md-5 = f.input :source
5
+ .col-md-5 = f.input :destination
6
+ .col-md-2 = f.input :active
@@ -0,0 +1,13 @@
1
+ tr
2
+ td
3
+ span.glyphicon class=glyph_bool(redirector_rule.active)
4
+ td = redirector_rule.source
5
+ td = redirector_rule.destination
6
+ td.actions.text-right
7
+ = link_to [:edit, redirector_rule], class: 'btn btn-sm btn-default'
8
+ i.glyphicon.glyphicon-pencil
9
+ = t('common.edit')
10
+ '
11
+ = link_to [redirector_rule], method: :delete, class: 'btn btn-sm btn-warning'
12
+ i.glyphicon.glyphicon-pencil
13
+ = t('common.delete')
@@ -0,0 +1,16 @@
1
+ = simple_form_for @redirector_rule do |f|
2
+ .content-header
3
+ h1
4
+ span.glyphicon.glyphicon-random
5
+ span.text
6
+ =< t '.edit'
7
+ = @redirector_rule.source.truncate 40
8
+
9
+ .content
10
+ .box
11
+ .box-content
12
+ = render 'form', f: f
13
+ .box-footer
14
+ .for-horizontal-form
15
+ = link_to t('common.back'), redirector_rules_path, class: 'btn btn-default'
16
+ = f.button :submit, class: 'btn btn-primary'
@@ -0,0 +1,34 @@
1
+ .content-header
2
+ h1
3
+ span.glyphicon.glyphicon-random
4
+ span.text =< t '.title'
5
+
6
+ ol.breadcrumb
7
+ li = link_to t('admin.common.home'), main_app.admin_root_path
8
+ li.active
9
+ strong =< t '.title'
10
+
11
+ .content
12
+ .box
13
+ .box-header
14
+ .heading
15
+ h3 = t('.list')
16
+ .actions
17
+ = link_to new_redirector_rules_import_path, class: 'btn btn-primary'
18
+ .glyphicon.glyphicon-random
19
+ = t('.import')
20
+ '
21
+ = link_to new_redirector_rule_path, class: 'btn btn-success'
22
+ .glyphicon.glyphicon-plus
23
+ = t('.create')
24
+
25
+ .box-content
26
+ table.table.table-striped
27
+ thead
28
+ tr
29
+ th = RedirectorRule.human_attribute_name :active
30
+ th = RedirectorRule.human_attribute_name :source
31
+ th = RedirectorRule.human_attribute_name :destination
32
+ th
33
+ tbody
34
+ = render(@redirector_rules) || render('empty')
@@ -0,0 +1,14 @@
1
+ = simple_form_for @redirector_rule do |f|
2
+ .content-header
3
+ h1
4
+ span.glyphicon.glyphicon-random
5
+ span.text =< t '.create'
6
+
7
+ .content
8
+ .box
9
+ .box-content
10
+ = render 'form', f: f
11
+ .box-footer
12
+ .for-horizontal-form
13
+ = link_to t('common.back'), redirector_rules_path, class: 'btn btn-default'
14
+ = f.button :submit, class: 'btn btn-primary'
@@ -0,0 +1,16 @@
1
+ = simple_form_for :redirector_rule, url: redirector_rules_imports_path do |f|
2
+ .content-header
3
+ h1
4
+ span.glyphicon.glyphicon-random
5
+ span.text =< t '.list'
6
+
7
+ .content
8
+ .box
9
+ .box-content
10
+ = f.input :file_import, as: :hidden
11
+ = f.input :file, as: :file, label: t('.file_import')
12
+
13
+ .box-footer
14
+ .for-horizontal-form
15
+ = link_to t('common.back'), redirector_rules_path, class: 'btn btn-default'
16
+ = f.button :submit, t('.import'), class: 'btn btn-primary'
@@ -0,0 +1,37 @@
1
+ doctype html
2
+ html
3
+ head
4
+ = metamagic site: 'Admin - Přesměrování',
5
+ title: [:title, :site],
6
+ separator: ' – '
7
+ meta charset='utf-8'
8
+ meta name='viewport' content='width=device-width, initial-scale=1.0'
9
+ = stylesheet_link_tag :admin, media: 'all'
10
+ = csrf_meta_tags
11
+
12
+ body class=body_class
13
+ .wrapper
14
+ .sidebar
15
+ ul.sidebar-menu
16
+ li.logo = link_to image_tag('admin/blueberry-logo.png'), main_app.admin_root_path
17
+ li = link_to t('.main_app'), main_app.admin_root_path
18
+ li = link_to t('.redirector_rules'), [:redirector_rules]
19
+
20
+ .content-wrapper
21
+ .header
22
+ nav.navbar.navbar-static-top role="navigation"
23
+ .navbar-custom-menu
24
+ ul.nav.navbar-nav
25
+ li
26
+ = link_to '#'
27
+ i.glyphicon.glyphicon-user>
28
+ span.role = current_administrator.email.split('@').first
29
+ li
30
+ = link_to main_app.destroy_administrator_session_path, method: :delete, title: t('.logout')
31
+ i.glyphicon.glyphicon-log-out
32
+
33
+ = render 'application/flashes'
34
+ = yield
35
+
36
+ = javascript_include_tag :admin
37
+ = yield :javascript
@@ -0,0 +1,46 @@
1
+ cs:
2
+ activerecord:
3
+ attributes:
4
+ redirect_rule:
5
+ source: 'Zdroj'
6
+ destination: 'Cíl'
7
+ active: 'Aktivní'
8
+ models:
9
+ redirect_rule: 'přesměrování'
10
+ redirector_rule: 'přesměrování'
11
+ blueberry_redirector:
12
+ redirector_rules:
13
+ create:
14
+ success: 'Záznam přesměrování byl úspěšně vytvořen'
15
+ destroy:
16
+ success: 'Záznam přesměrování byl úspěšně smazán'
17
+ edit:
18
+ back: "Zpět"
19
+ edit: "Úprava přesměrování"
20
+ empty:
21
+ no_redirector_rules: "Nenalezena žádná pravidla přesměrování."
22
+ form:
23
+ main: "Hlavní informace"
24
+ index:
25
+ list: "Seznam přesměrování"
26
+ create: "Vytvořit přesměrování"
27
+ title: "Přesměrování"
28
+ new:
29
+ back: "Zpět"
30
+ create: "Vytvořit přesměrování"
31
+ new_import:
32
+ back: "Zpět"
33
+ import: "Importovat"
34
+ list: "Importovat přesměrování z xlsx"
35
+ file_import: 'Soubor s přesměrováním (xlsx)'
36
+ update:
37
+ success: 'Záznam přesměrování byl úspěšně upraven'
38
+ redirector_rules_imports:
39
+ create:
40
+ wrong_format: 'Záznamy přesměrování nemohly být naimportovány, špatný formát souboru.'
41
+ success: 'Import záznamů přesměrování proběhl úspěšně'
42
+ layouts:
43
+ blueberry_redirector:
44
+ application:
45
+ redirector_rules: 'Přesměrování'
46
+ main_app: 'Hlavní administrace'
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ BlueberryRedirector::Engine.routes.draw do
2
+ resources :redirector_rules, except: :show
3
+ resources :redirector_rules_imports, only: %i(new create)
4
+ root to: 'redirector_rules#index'
5
+ end
@@ -0,0 +1,28 @@
1
+ class CreateRedirectRules < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :redirect_rules do |t|
4
+ t.string :source, null: false
5
+ t.boolean :source_is_regex, null: false, default: false
6
+ t.boolean :source_is_case_sensitive, null: false, default: false
7
+ t.string :destination, null: false
8
+ t.boolean :active, default: false
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :request_environment_rules do |t|
13
+ t.integer :redirect_rule_id, null: false
14
+ t.string :environment_key_name, null: false
15
+ t.string :environment_value, null: false
16
+ t.boolean :environment_value_is_regex, null: false, default: false
17
+ t.boolean :environment_value_is_case_sensitive, null: false, default: true
18
+ t.timestamps
19
+ end
20
+
21
+ add_index :redirect_rules, :source
22
+ add_index :redirect_rules, :active
23
+ add_index :redirect_rules, :source_is_regex
24
+ add_index :redirect_rules, :source_is_case_sensitive
25
+
26
+ add_index :request_environment_rules, :redirect_rule_id
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ require "blueberry_redirector/engine"
2
+ require "redirector"
3
+
4
+ module BlueberryRedirector
5
+ end
@@ -0,0 +1,14 @@
1
+ module BlueberryRedirector
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace BlueberryRedirector
4
+
5
+ engine_name 'redirector'
6
+
7
+ initializer 'redirector.apply_options' do |app|
8
+ config = app.config.redirector
9
+ config.blacklisted_extensions = %w(.js .css .jpg .png .woff .ttf .woff2 .ico .svg)
10
+ config.use_environment_variables = false
11
+ config.include_query_in_source = true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module BlueberryRedirector
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :blueberry_redirector do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blueberry_redirector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tonda Pleskac
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: roo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: simplify_redirector
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
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: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Description of BlueberryRedirector.
84
+ email:
85
+ - pleskac@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - MIT-LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - app/controllers/blueberry_redirector/application_controller.rb
94
+ - app/controllers/blueberry_redirector/redirector_rules_controller.rb
95
+ - app/controllers/blueberry_redirector/redirector_rules_imports_controller.rb
96
+ - app/helpers/blueberry_redirector/redirector_helper.rb
97
+ - app/models/redirector_rule.rb
98
+ - app/services/import_redirect_rules.rb
99
+ - app/services/service.rb
100
+ - app/views/blueberry_redirector/redirector_rules/_empty.html.slim
101
+ - app/views/blueberry_redirector/redirector_rules/_form.html.slim
102
+ - app/views/blueberry_redirector/redirector_rules/_redirector_rule.html.slim
103
+ - app/views/blueberry_redirector/redirector_rules/edit.html.slim
104
+ - app/views/blueberry_redirector/redirector_rules/index.html.slim
105
+ - app/views/blueberry_redirector/redirector_rules/new.html.slim
106
+ - app/views/blueberry_redirector/redirector_rules/new_import.html.slim
107
+ - app/views/layouts/blueberry_redirector/application.html.slim
108
+ - config/locales/cs.yml
109
+ - config/routes.rb
110
+ - db/migrate/20170126132346_create_redirect_rules.rb
111
+ - lib/blueberry_redirector.rb
112
+ - lib/blueberry_redirector/engine.rb
113
+ - lib/blueberry_redirector/version.rb
114
+ - lib/tasks/blueberry_redirector_tasks.rake
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.5.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Summary of BlueberryRedirector.
139
+ test_files: []