refinerycms-routes 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ class CreateRoutes < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :routes do |t|
5
+ t.string :url
6
+ t.string :locale
7
+ t.boolean :redirect, :default => false
8
+ t.integer :target_id
9
+ t.string :target_type
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_index :routes, :url
15
+ add_index :routes, [:target_id, :target_type]
16
+
17
+ load(Rails.root.join('db', 'seeds', 'routes.rb'))
18
+ end
19
+
20
+ def self.down
21
+ UserPlugin.destroy_all({:name => "refinerycms_routes"})
22
+
23
+ drop_table :routes
24
+ end
25
+
26
+ end
@@ -0,0 +1,28 @@
1
+ User.all.each do |user|
2
+ if user.plugins.where(:name => 'refinerycms_routes').blank?
3
+ user.plugins.create(:name => 'refinerycms_routes',
4
+ :position => (user.plugins.maximum(:position) || -1) +1)
5
+ end
6
+ end
7
+
8
+ def url_for(options = {})
9
+ url = case options
10
+ when String
11
+ options.gsub('/', '')
12
+ when Hash
13
+ options = options[:path].join('/')
14
+ end
15
+ url
16
+ end
17
+
18
+ Page.all.each do |page|
19
+ page.translations.map(&:locale).each do |locale|
20
+ page_url = url_for(page.url)
21
+
22
+ unless locale == ::Refinery::I18n.default_frontend_locale
23
+ page_url = "#{locale}#{ '/' unless page_url.blank? }#{page_url}"
24
+ end
25
+
26
+ Route.create(:url => page_url, :locale => locale, :target => page)
27
+ end
28
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-routes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Charles Barbier
@@ -46,6 +46,8 @@ files:
46
46
  - app/views/admin/routes/edit.html.erb
47
47
  - app/views/admin/routes/index.html.erb
48
48
  - app/views/admin/routes/new.html.erb
49
+ - db/migrate/1_create_routes.rb
50
+ - db/seeds/routes.rb
49
51
  homepage: http://github.com/unixcharles/refinerycms-copywriting
50
52
  licenses: []
51
53