couch_i18n 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -9,9 +9,51 @@ database type:
9
9
  Now all translations are ported to the database. If you change then now in the
10
10
  yaml files, they will nolonger be displayed in the website. They should be managed
11
11
  in the database. This gem also provides a translation management system. To place this
12
- in your own design, create a file _config/initializers/couch_i18n.rb_ with the
12
+ in your own design, create a file _app/views/layouts/couch_i18n/application.html.haml_ with the
13
13
  following content:
14
- CouchI18n::ApplicationController.layout 'application'
14
+ = render :template => '/layouts/application'
15
+ Or create your own really nice template. Let me know if there is a nice layout!
15
16
  Your Gemfile should look like:
17
+ gem 'simply_stored', :git => 'git://github.com/bterkuile/simply_stored.git'
16
18
  gem 'couch_i18n'
17
19
  gem 'kaminari'
20
+ And in your config routes put:
21
+ namespace :couch_i18n do
22
+ root :to => "stores#index"
23
+ resources :stores
24
+ end
25
+ Or to put is at a different location:
26
+ namespace :translations, :module => :couch_i18n, :as => 'couch_i18n' do
27
+ root :to => "stores#index"
28
+ resources :stores
29
+ end
30
+ The intention is to make this a mountable application, but this will not happen
31
+ before Rails 3.1 is officially out. But beware of using this if your application
32
+ will not be Rails 3.1 compatible.
33
+
34
+ == Security!!!
35
+ By default there is no security activated for editing the translation. This is
36
+ a choice since you should be in control over your own security. To help you
37
+ securing the translations in your application I will describe the steps I did
38
+ to add declarative_authorization security into the translation. Start with an
39
+ initializer: _config/initializers/couch_I18n_modifications.rb_
40
+ require 'couch_i18n/application_controller'
41
+ module CouchI18n
42
+ class ApplicationController
43
+ def current_user
44
+ Authorization.current_user
45
+ end
46
+ include Authorization::AuthorizationInController
47
+ filter_access_to :all
48
+ def permission_denied
49
+ redirect_to root_path, :alert => I18n.t('authorization.not_authorized')
50
+ end
51
+ end
52
+ end
53
+ And in _config/authorization_rules.rb_ put your personalized version of:
54
+ role :translator do
55
+ has_permission_on :couch_i18n_stores, :to => :manage
56
+ end
57
+ Beware that a permission denied message will appear when the server is restarted
58
+ this way. This is because the current user is set in ApplicationController which
59
+ is not part of the CouchI18n controller stack.
@@ -0,0 +1,10 @@
1
+ = form_for @couch_i18n_store do |f|
2
+ = render 'shared/error_messages', :target => @couch_i18n_store
3
+ .field
4
+ = f.label :key
5
+ = f.text_field :key, :size => 70
6
+ .field
7
+ = f.label :value
8
+ = f.text_field :value
9
+ .actions
10
+ = f.submit @submit || update_button_text
@@ -0,0 +1,4 @@
1
+ - title t("couch_i18n.store.Edit title")
2
+ = render 'form'
3
+ - content_for :page_links do
4
+ = link_to link_to_index_content(:couch_i18n_stores), couch_i18n_stores_path(:offset => params[:offset])
@@ -0,0 +1,31 @@
1
+ - title t("couch_i18n.store.Index title")
2
+ - for offset in @available_higher_offsets
3
+ = link_to offset[:name], :offset => offset[:offset]
4
+ = form_tag({}, :method => :get )do
5
+ - if params[:offset].present?
6
+ = link_to 'x', :offset => nil
7
+ = text_field_tag :offset, params[:offset], :size => 60
8
+ = "(#{@couch_i18n_stores.total_entries})"
9
+ = submit_tag 'Select offset'
10
+ - for offset in @available_deeper_offsets
11
+ = link_to offset[:name], :offset => offset[:offset]
12
+ - if @couch_i18n_stores.any?
13
+ = paginate @couch_i18n_stores, :right => 3, :left => 3
14
+ %table.index-table
15
+ %thead
16
+ %tr
17
+ %th= CouchI18n::Store.human_attribute_name(:key)
18
+ %th= CouchI18n::Store.human_attribute_name(:value)
19
+ %th
20
+ %tbody
21
+ - @couch_i18n_stores.each do |couch_i18n_store|
22
+ %tr
23
+ %td= link_to couch_i18n_store.key[(params[:offset].try(:size) || 0)..-1].sub(/^\./, ''), edit_couch_i18n_store_path(couch_i18n_store)
24
+ %td= link_to couch_i18n_store.value, edit_couch_i18n_store_path(couch_i18n_store)
25
+ %td= link_to link_to_edit_content(couch_i18n_store), edit_couch_i18n_store_path(couch_i18n_store)
26
+ %td= link_to link_to_destroy_content(couch_i18n_store),couch_i18n_store_path(couch_i18n_store), :confirm => are_you_sure, :method => :delete
27
+ - else
28
+ %h3= t("couch_i18n_store.None found")
29
+
30
+ - content_for :page_links do
31
+ = link_to link_to_new_content(:couch_i18n_store), new_couch_i18n_store_path(:offset => params[:offset])
@@ -0,0 +1,4 @@
1
+ - title t("couch_i18n.store.New title")
2
+ = render 'form'
3
+ - content_for :page_links do
4
+ = link_to link_to_index_content(:couch_i18n_stores), couch_i18n_stores_path(:offset => params[:offset])
@@ -31,7 +31,7 @@ module CouchI18n
31
31
  end
32
32
 
33
33
  def self.get_keys_by_level(level = 0, options = {})
34
- data = database.view(with_key_array(options.merge(:group => true, :group_level => level.succ)))["rows"]
34
+ data = database.view(with_key_array(options.merge(:group_level => level.succ)))["rows"]
35
35
  # data = data.select{|h| h["key"].size > level } # Only select ones that have a deeper nesting
36
36
  data.map{|h| h['key'][level].try(:to_sym)}.compact
37
37
  end
data/lib/couch_i18n.rb CHANGED
@@ -30,3 +30,6 @@ module CouchI18n
30
30
  return store
31
31
  end
32
32
  end
33
+
34
+ # Now extend the I18n backend
35
+ I18n.backend = I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(CouchI18n::Store), I18n.backend)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Benjamin ter Kuile
@@ -18,7 +18,7 @@ date: 2011-05-15 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: couch_i18n deliveres an in database storage for I18n translations, tested for rails
21
+ description: couch_i18n is an in database storage for I18n translations, tested for rails, with online management views
22
22
  email: bterkuile@gmail.com
23
23
  executables: []
24
24
 
@@ -36,6 +36,10 @@ files:
36
36
  - app/assets/javascripts/application.js
37
37
  - app/assets/stylesheets/application.css
38
38
  - app/helpers/couch_i18n/application_helper.rb
39
+ - app/views/couch_i18n/stores/_form.html.haml
40
+ - app/views/couch_i18n/stores/index.html.haml
41
+ - app/views/couch_i18n/stores/edit.html.haml
42
+ - app/views/couch_i18n/stores/new.html.haml
39
43
  - app/views/layouts/couch_i18n/application.html.haml
40
44
  - MIT-LICENSE
41
45
  - Rakefile
@@ -69,6 +73,6 @@ rubyforge_project: couch_i18n
69
73
  rubygems_version: 1.3.6
70
74
  signing_key:
71
75
  specification_version: 3
72
- summary: couch_i18n deliveres an in database storage for I18n translations, tested for rails
76
+ summary: couch_i18n is an in database storage for I18n translations, tested for rails, with online management views
73
77
  test_files: []
74
78