Permalink
Browse files

Fixed locale and added FormHelper

  • Loading branch information...
1 parent 624c0b2 commit 1c0111329597a2504ec58352ca887a408e185210 @komagata committed Nov 9, 2011
Showing with 39 additions and 39 deletions.
  1. +1 −0 README.md
  2. +19 −14 lib/lokka/redirect.rb
  3. +8 −10 views/rules/edit.haml
  4. +3 −6 views/rules/index.haml
  5. +8 −9 views/rules/new.haml
View
@@ -6,6 +6,7 @@ This plugin is for the website using Lokka deployed on Heroku. The plugin can cr
$ cd LOKKA_ROOT/public/plugin
$ git clone git@github.com:champierre/lokka-redirect.git
+ $ rm -rf lokka-redirect/.git
## Usage
View
@@ -1,5 +1,7 @@
module Lokka
module Redirect
+ class Rule < OpenStruct; end
+
def self.registered(app)
app.get '/admin/plugins/redirect' do
redirect '/admin/plugins/redirect/rules'
@@ -11,44 +13,47 @@ def self.registered(app)
end
app.get '/admin/plugins/redirect/rules/new' do
+ @rule = Rule.new
haml :"plugin/lokka-redirect/views/rules/new", :layout => :"admin/layout"
end
app.post '/admin/plugins/redirect/rules' do
- @rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
- @rules.push params['rule']
- Option.lokka_redirect_rules = @rules.to_json
+ rule = params[:lokka_redirect_rule]
+ rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
+ rules.push rule
+ Option.lokka_redirect_rules = rules.to_json
flash[:notice] = 'Redirect Rule was successfully created.'
redirect '/admin/plugins/redirect/rules'
end
app.get '/admin/plugins/redirect/rules/:id/edit' do |id|
- @rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
- @rule = @rules[id.to_i]
+ rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
+ @rule = Rule.new(rules[id.to_i])
+ @rule.id = id
haml :"plugin/lokka-redirect/views/rules/edit", :layout => :"admin/layout"
end
app.put '/admin/plugins/redirect/rules/:id' do |id|
- @rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
- @rules[id.to_i] = params['rule']
- Option.lokka_redirect_rules = @rules.to_json
+ rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
+ rules[id.to_i] = params[:lokka_redirect_rule]
+ Option.lokka_redirect_rules = rules.to_json
flash[:notice] = 'Redirect Rule was successfully updated.'
redirect '/admin/plugins/redirect/rules'
end
app.delete '/admin/plugins/redirect/rules/:id' do |id|
- @rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
- @rules.delete_at(id.to_i)
- Option.lokka_redirect_rules = @rules.to_json
+ rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
+ rules.delete_at(id.to_i)
+ Option.lokka_redirect_rules = rules.to_json
flash[:notice] = 'Redirect Rule was successfully deleted.'
redirect '/admin/plugins/redirect/rules'
end
app.get '*' do |path|
pass if path =~ /^\/admin\//
- @rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
- @rules.each do |rule|
+ rules = Option.lokka_redirect_rules ? JSON.parse(Option.lokka_redirect_rules) : []
+ rules.each do |rule|
pattern = rule['pattern']
substitution = rule['substitution']
if pattern && substitution
@@ -62,4 +67,4 @@ def self.registered(app)
end
end
end
-end
+end
View
@@ -1,13 +1,11 @@
%h2 Edit Redirect Rule
-%form{:action => "/admin/plugins/redirect/rules/#{params[:id]}", :method => 'post'}
- %input{:type => 'hidden', :name => '_method', :value => 'put'}
+- form_for @rule, "/admin/plugins/redirect/rules/#{@rule.id}", :method => 'put' do |f|
.field
- %label{:for => 'rule_pattern'} Pattern
- %br
- %input{:type => 'text', :id => 'rule_pattern', :name => 'rule[pattern]', :value => @rule['pattern']}
+ = f.label :pattern
+ %br/
+ = f.text_field :pattern
.field
- %label{:for => 'rule_substitution'} Substitution
- %br
- %input{:type => 'text', :id => 'rule_substitution', :name => 'rule[substitution]', :value => @rule['substitution']}
- %p
- %input{:type => 'submit', :value => t.edit}
+ = f.label :substitution
+ %br/
+ = f.text_field :substitution
+ %p= f.submit t('edit')
@@ -23,9 +23,6 @@
%tr{:class => (i+1).odd? ? 'odd' : 'even'}
%td= rule['pattern']
%td= rule['substitution']
- %td
- %a.button{:href => "/admin/plugins/redirect/rules/#{i}/edit"}= t.edit
- %td
- = link_to t.delete, "/admin/plugins/redirect/rules/#{i}", :class => 'button', :confirm => t.are_you_sure, :method => :delete
-%div
- %a.button{:href => "/admin/plugins/redirect/rules/new"}= t.new
+ %td= link_to t('edit'), "/admin/plugins/redirect/rules/#{i}/edit", :class => 'button'
+ %td= link_to t('delete'), "/admin/plugins/redirect/rules/#{i}", :class => 'button', :confirm => t('are_you_sure'), :method => :delete
+= link_to t('new'), "/admin/plugins/redirect/rules/new", :class => 'button'
View
@@ -1,12 +1,11 @@
%h2 New Redirect Rule
-%form{:action => '/admin/plugins/redirect/rules', :method => 'post'}
+- form_for @rule, '/admin/plugins/redirect/rules', :method => 'post' do |f|
.field
- %label{:for => 'rule_pattern'} Pattern
- %br
- %input{:type => 'text', :id => 'rule_pattern', :name => 'rule[pattern]'}
+ = f.label :pattern
+ %br/
+ = f.text_field :pattern
.field
- %label{:for => 'rule_substitution'} Substitution
- %br
- %input{:type => 'text', :id => 'rule_substitution', :name => 'rule[substitution]'}
- %p
- %input{:type => 'submit', :value => t.new}
+ = f.label :substitution
+ %br/
+ = f.text_field :substitution
+ %p= f.submit t('new')

0 comments on commit 1c01113

Please sign in to comment.