tenon 1.0.20 → 1.0.21

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: c3848f32e34e0f1e0460ade450a9efd9aa35d13a
4
- data.tar.gz: 2f2ee2e3c2d31c33116a4bde4cea1be713c708fd
3
+ metadata.gz: 6e5748fcf9b196fa90e2d8e40df6f4c95591ec12
4
+ data.tar.gz: 86540071e3cf945fc681c4fc1cb17358a4814a98
5
5
  SHA512:
6
- metadata.gz: f33bc073e606b9e340bd17c756717690a45ab36fe9f71e0e3023a1f203108be2cceb2057cc39b9e30b3f7dfcaab906a6f5e31499ac080fc45905933f92c281cc
7
- data.tar.gz: 44be645d288dc1d361b32017133844d056526f2f6670bb666b193196eff81e9db0d9e6f49fecac45c45a5c675552f7c48ea1bbbe2c1228a77c21972cbe45eeed
6
+ metadata.gz: 40d31fc0db7542758b6439eacdda83b322137d90870fe66fa53d437c0b708e0bd1621dd5c590575119e0baa0cfe2a12f7cd4ed71a4a568dfc9821f4b15925dcf
7
+ data.tar.gz: 6d0de504e06a23e40fc462b5cedf7f8d4be006b48ccc159bf02de51d44b5d6a6c75b35f97a5ad54cab5f1f63556a858c79e9efbfc1430090432a41467aae46c2
@@ -0,0 +1,20 @@
1
+ <li data-record-id="<%= @redirect.id %>">
2
+ <div class="record-details">
3
+ <div class="record-actions">
4
+ <%- @redirect.delete_link %>
5
+ <%- @redirect.edit_link %>
6
+ <% if @redirect.active == true: %>
7
+ <a data-tooltip="Active"><i class="fa fa-eye fa-fw"></i></span>
8
+ <% end %>
9
+ </div>
10
+
11
+ <div class="record-title">
12
+ <a href="<%= @redirect.edit_path %>">
13
+ /<%= @redirect.in %>/
14
+ <i class="fa fa-long-arrow-right" style="margin: 0 20px; opacity:0.3;" />
15
+ <%= @redirect.out %>
16
+ </a>
17
+ </div>
18
+
19
+ </div>
20
+ </li>
@@ -0,0 +1,13 @@
1
+ module Tenon
2
+ class RedirectsController < Tenon::ResourcesController
3
+ def resource_params
4
+ params.require(:redirect).permit!
5
+ end
6
+
7
+ private
8
+
9
+ def search_args
10
+ ["#{klass.table_name}.in ILIKE ? OR #{klass.table_name}.out ILIKE ?", "%#{params[:q]}%", "%#{params[:q]}%"]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ class Tenon::RedirectDecorator < Tenon::ApplicationDecorator
2
+ end
@@ -0,0 +1,13 @@
1
+ class Tenon::Redirect < ActiveRecord::Base
2
+ # Scopes, attachments, etc.
3
+ has_history
4
+ include Tenon::Reorderable
5
+
6
+ default_scope { order('tenon_redirects.list_order') }
7
+ scope :active, -> { where(active: true) }
8
+
9
+ # Validations
10
+ validates_presence_of :in, :out
11
+ validates_uniqueness_of :in
12
+
13
+ end
@@ -0,0 +1,52 @@
1
+ # If the app catches a 404, check Redirect records for a match.
2
+
3
+ # Use -> Add the following to application_controller.rb:
4
+ # rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
5
+ # private
6
+ # def record_not_found
7
+ # redirect_to Tenon::Redirector.redirect(request)
8
+ # end
9
+
10
+ module Tenon
11
+ class Redirector
12
+ def initialize(path, redirects = Tenon::Redirect.active)
13
+ @path = path
14
+ @redirects = redirects
15
+ end
16
+
17
+ def redirect
18
+ # If 404 -> Compare the path to all Redirect records:
19
+ @destination = get_destination
20
+ # raise @destination.inspect
21
+ if @destination.present?
22
+ # If there is a match return destination:
23
+ return @destination
24
+ else
25
+ # Else -> trigger the 404 again:
26
+ raise ActiveRecord::RecordNotFound
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def get_destination
33
+ @redirects.each do |redirect|
34
+ if @path.match(/#{redirect.in}/).present?
35
+ return redirect_match(redirect)
36
+ end
37
+ end
38
+ nil
39
+ end
40
+
41
+ def redirect_match(redirect)
42
+ @destination = redirect.out
43
+ captures = @path.match(/#{redirect.in}/).captures
44
+ if captures.present?
45
+ captures.each_with_index do |capture, i|
46
+ @destination = @destination.gsub(/\{#{i}\}/, capture)
47
+ end
48
+ end
49
+ @destination
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,42 @@
1
+ - content_for :sidebar do
2
+ .sidebar
3
+ .content
4
+ %h2 Redirects
5
+ = link_to "New Redirect", new_redirect_path, class: 'btn btn-block btn-primary'
6
+
7
+ = autosaving_form_for @redirect do |f|
8
+ .flash.flash-alert{style: 'padding-right: 40px;'}
9
+ %i.fa.fa-exclamation-triangle
10
+ Redirects will be run when a page cannot be found. It will not redirect an existing page.
11
+
12
+ = error_messages_for :redirect
13
+ .fields.large.tabs
14
+ .tab-pane.active#details
15
+ .form-group
16
+ = f.text_field :in, label: 'Route to match', explanation: 'String, can be written as a regular expression (without opening and closing /)', placeholder: '\/old-path\/(\d+)-(\.*)'
17
+ .form-group
18
+ = f.text_field :out, label: 'Destination', explanation: 'Zero-indexed captures can be returned in {x}', placeholder: '/new-path/{0}-{1}'
19
+
20
+ .fields.small
21
+ %h4.box-label Details
22
+ .box
23
+ .form-group.bordered.inline
24
+ = f.check_box :active, class: 'tn-checkbox-right'
25
+ = f.super_label :active
26
+
27
+ %h4.box-label Actions
28
+ .box
29
+ .content
30
+ - if can?(:publish, @redirect)
31
+ %button.btn.btn-block.btn-comp Save
32
+ - if can?(:create, Tenon::ItemVersion)
33
+ = save_draft_button(@redirect)
34
+ .last-autosave
35
+
36
+ %hr
37
+ .content
38
+ = clear_draft_link if params[:version]
39
+ = load_draft_link(@redirect)
40
+ - if @redirect.persisted?
41
+ = link_to "Delete", @redirect, data: {method: :delete, confirm: 'Are you sure you want to delete this?'}, :class => 'delete-link'
42
+ .spacer
@@ -0,0 +1 @@
1
+ json.extract!(redirect, :id, :in, :out, :active, :edit_path, :edit_link, :delete_link)
@@ -0,0 +1,8 @@
1
+ %header
2
+ %h1 Edit Redirect
3
+
4
+ .tools
5
+ = render "tenon/shared/section_header/sidebar_toggle"
6
+
7
+ .main-content
8
+ = render "form"
@@ -0,0 +1,29 @@
1
+ - content_for :sidebar do
2
+ .sidebar
3
+ .content
4
+ %h2 Redirects
5
+ = link_to "New Redirect", new_redirect_path, class: 'btn btn-block btn-primary'
6
+ %p Drag and drop to set priority.
7
+
8
+ %header
9
+ %h1 Redirects
10
+
11
+ .tools
12
+ = render "tenon/shared/section_header/sidebar_toggle"
13
+
14
+ .header-button
15
+ = link_to '#', id: 'quick-search-toggle' do
16
+ .header-icon= fa_icon('fw search')
17
+
18
+ .toolbox
19
+ = render "tenon/shared/section_header/quick_search", record_list: '#redirects'
20
+
21
+ .main-content
22
+ .flash.flash-alert{style: 'padding-right: 40px;'}
23
+ %i.fa.fa-exclamation-triangle
24
+ Redirects will be run when a page cannot be found. It will not redirect an existing page.
25
+
26
+ = error_messages_for :redirect
27
+ %ul#redirects.record-list.sortable{data: {records: {url: redirects_path(format: 'json'), template: 'tenon/templates/redirects/redirect_row', name: 'redirect'}, :'reorder-path' => reorder_redirects_path}}
28
+
29
+ = link_to "Load More Redirects", '#', :class => 'btn btn-comp infinite-loader', 'data-record-list' => '#redirects'
@@ -0,0 +1,5 @@
1
+ json.records do
2
+ json.partial! 'redirect', collection: @redirects, as: :redirect
3
+ end
4
+
5
+ json.partial!('tenon/shared/pagination', collection: @redirects)
@@ -0,0 +1,8 @@
1
+ %header
2
+ %h1 New Redirect
3
+
4
+ .tools
5
+ = render "tenon/shared/section_header/sidebar_toggle"
6
+
7
+ .main-content
8
+ = render "form"
@@ -10,4 +10,5 @@
10
10
  = nav_item 'Events', events_path, 'calendar'
11
11
  = nav_item 'Galleries', galleries_path, 'th'
12
12
  = nav_item 'Contacts', contacts_path, 'envelope'
13
+ = nav_item 'Redirects', redirects_path, 'exchange'
13
14
  = nav_item 'Settings', settings_path, 'gear'
data/config/routes.rb CHANGED
@@ -41,9 +41,14 @@ Tenon::Engine.routes.draw do
41
41
  post 'reorder', :on => :collection
42
42
  end
43
43
 
44
+ resources :redirects do
45
+ post 'reorder', :on => :collection
46
+ end
47
+
44
48
  resources :users, :except => [:show] do
45
49
  get 'approve', :on => :member
46
50
  end
47
51
 
48
52
  root :to => 'index#index'
49
53
  end
54
+
@@ -0,0 +1,12 @@
1
+ class CreateTenonRedirects < ActiveRecord::Migration
2
+ def change
3
+ create_table :tenon_redirects do |t|
4
+ t.string :in
5
+ t.string :out
6
+ t.integer :list_order, default: 0
7
+ t.boolean :active, default: true
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :tenon_redirect, class: Tenon::Redirect do
3
+ sequence(:title) { |n| "Test Page - #{n}" }
4
+ 'in' '\/on-the-floor\/(\d+-.*)'
5
+ 'out' '/posts/{0}'
6
+ end
7
+ end
8
+
9
+
data/lib/tenon/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tenon
2
- VERSION = '1.0.20'
2
+ VERSION = '1.0.21'
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tenon::Redirect do
4
+ describe '.active' do
5
+ it 'should find redirects that are active' do
6
+ expect(Tenon::Redirect).to receive(:where).with(active: true)
7
+ Tenon::Redirect.active
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tenon::Redirector do
4
+ describe '.redirect' do
5
+ before do
6
+ Tenon::Redirect.create(in: '\/a-page', out: '/new-page', list_order: 0)
7
+ Tenon::Redirect.create(in: '\/on-the-floor\/(\d+-.*)', out: '/posts/{0}', list_order: 1)
8
+ Tenon::Redirect.create(in: '\/on-the-floor.*', out: '/posts', list_order: 2)
9
+ end
10
+
11
+ context 'finds a redirect match' do
12
+ it 'should return a destination path' do
13
+ redirector = Tenon::Redirector.new('/a-page')
14
+ expect(redirector.redirect).to eq('/new-page')
15
+ end
16
+
17
+ it 'should return the first match ordered by list_order' do
18
+ redirector = Tenon::Redirector.new('/on-the-floor/1-something')
19
+ expect(redirector.redirect).to eq('/posts/1-something')
20
+ end
21
+ end
22
+
23
+ context 'does not find a redirect match' do
24
+ it 'should raise 404' do
25
+ redirector = Tenon::Redirector.new('/not-on-the-floor/1-something')
26
+ expect{ redirector.redirect }.to raise_error{ ActiveRecord::RecordNotFound }
27
+ end
28
+ end
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tenon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.20
4
+ version: 1.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - factor[e] design initiative
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-19 00:00:00.000000000 Z
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_errors
@@ -993,6 +993,7 @@ files:
993
993
  - app/assets/javascripts/tenon/templates/pages/page_row.jst.eco
994
994
  - app/assets/javascripts/tenon/templates/post_categories/post_category_row.jst.eco
995
995
  - app/assets/javascripts/tenon/templates/posts/post_row.jst.eco
996
+ - app/assets/javascripts/tenon/templates/redirects/redirect_row.jst.eco
996
997
  - app/assets/javascripts/tenon/templates/tenon_callouts/tenon_callout_row.jst.eco
997
998
  - app/assets/javascripts/tenon/templates/tenon_content/popped_out.jst.eco
998
999
  - app/assets/javascripts/tenon/templates/users/user_row.jst.eco
@@ -1056,6 +1057,7 @@ files:
1056
1057
  - app/controllers/tenon/pages_controller.rb
1057
1058
  - app/controllers/tenon/post_categories_controller.rb
1058
1059
  - app/controllers/tenon/posts_controller.rb
1060
+ - app/controllers/tenon/redirects_controller.rb
1059
1061
  - app/controllers/tenon/resources_controller.rb
1060
1062
  - app/controllers/tenon/settings_controller.rb
1061
1063
  - app/controllers/tenon/simple_resources_controller.rb
@@ -1071,6 +1073,7 @@ files:
1071
1073
  - app/decorators/tenon/paginating_decorator.rb
1072
1074
  - app/decorators/tenon/post_category_decorator.rb
1073
1075
  - app/decorators/tenon/post_decorator.rb
1076
+ - app/decorators/tenon/redirect_decorator.rb
1074
1077
  - app/decorators/tenon/tenon_callout_decorator.rb
1075
1078
  - app/decorators/tenon/tenon_content/row_decorator.rb
1076
1079
  - app/decorators/tenon/user_decorator.rb
@@ -1099,6 +1102,7 @@ files:
1099
1102
  - app/models/tenon/photo.rb
1100
1103
  - app/models/tenon/post.rb
1101
1104
  - app/models/tenon/post_category.rb
1105
+ - app/models/tenon/redirect.rb
1102
1106
  - app/models/tenon/role.rb
1103
1107
  - app/models/tenon/role_assignment.rb
1104
1108
  - app/models/tenon/s3_direct_upload.rb
@@ -1125,6 +1129,7 @@ files:
1125
1129
  - app/models/tenon/tenon_content/row_types/two_column_text.rb
1126
1130
  - app/models/tenon/thinger.rb
1127
1131
  - app/models/tenon/user.rb
1132
+ - app/services/tenon/redirector.rb
1128
1133
  - app/views/devise/confirmations/new.html.erb
1129
1134
  - app/views/devise/confirmations/new.html.haml
1130
1135
  - app/views/devise/mailer/confirmation_instructions.html.erb
@@ -1197,6 +1202,12 @@ files:
1197
1202
  - app/views/tenon/posts/index.html.haml
1198
1203
  - app/views/tenon/posts/index.json.jbuilder
1199
1204
  - app/views/tenon/posts/new.html.haml
1205
+ - app/views/tenon/redirects/_form.html.haml
1206
+ - app/views/tenon/redirects/_redirect.json.jbuilder
1207
+ - app/views/tenon/redirects/edit.html.haml
1208
+ - app/views/tenon/redirects/index.html.haml
1209
+ - app/views/tenon/redirects/index.json.jbuilder
1210
+ - app/views/tenon/redirects/new.html.haml
1200
1211
  - app/views/tenon/settings/_contact.html.haml
1201
1212
  - app/views/tenon/settings/_general.html.haml
1202
1213
  - app/views/tenon/settings/_seo.html.haml
@@ -1289,6 +1300,7 @@ files:
1289
1300
  - db/migrate/20140520150508_add_publish_at_and_remove_published_from_tenon_posts.rb
1290
1301
  - db/migrate/20140520161213_remove_published_feld_from_tenon_pages.rb
1291
1302
  - db/migrate/20140619135927_add_stretch_boolean_to_tenon_tenon_content_pieces.rb
1303
+ - db/migrate/20140623142634_create_tenon_redirects.rb
1292
1304
  - db/seeds.rb
1293
1305
  - lib/generators/tenon/i18n_migrations/i18n_migrations_generator.rb
1294
1306
  - lib/generators/tenon/i18n_migrations/templates/migration.rb
@@ -1332,6 +1344,7 @@ files:
1332
1344
  - lib/tenon/factories/galleries.rb
1333
1345
  - lib/tenon/factories/pages.rb
1334
1346
  - lib/tenon/factories/posts.rb
1347
+ - lib/tenon/factories/redirects.rb
1335
1348
  - lib/tenon/factories/tenon_callouts.rb
1336
1349
  - lib/tenon/factories/users.rb
1337
1350
  - lib/tenon/has_asset.rb
@@ -1395,9 +1408,11 @@ files:
1395
1408
  - spec/models/tenon/my_settings_spec.rb
1396
1409
  - spec/models/tenon/page_spec.rb
1397
1410
  - spec/models/tenon/post_spec.rb
1411
+ - spec/models/tenon/redirect_spec.rb
1398
1412
  - spec/models/tenon/tenon_callout_spec.rb
1399
1413
  - spec/models/tenon/tenon_content/row_spec.rb
1400
1414
  - spec/models/tenon/user_spec.rb
1415
+ - spec/services/tenon/redirector_spec.rb
1401
1416
  - spec/spec_helper.rb
1402
1417
  - spec/support/integration_example_group.rb
1403
1418
  - spec/support/request_helpers.rb
@@ -1508,9 +1523,11 @@ test_files:
1508
1523
  - spec/models/tenon/my_settings_spec.rb
1509
1524
  - spec/models/tenon/page_spec.rb
1510
1525
  - spec/models/tenon/post_spec.rb
1526
+ - spec/models/tenon/redirect_spec.rb
1511
1527
  - spec/models/tenon/tenon_callout_spec.rb
1512
1528
  - spec/models/tenon/tenon_content/row_spec.rb
1513
1529
  - spec/models/tenon/user_spec.rb
1530
+ - spec/services/tenon/redirector_spec.rb
1514
1531
  - spec/spec_helper.rb
1515
1532
  - spec/support/integration_example_group.rb
1516
1533
  - spec/support/request_helpers.rb