typus 0.9.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. data/.gitignore +8 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +86 -0
  4. data/Rakefile +61 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/admin/master_controller.rb +354 -0
  7. data/app/controllers/typus_controller.rb +128 -0
  8. data/app/helpers/admin/form_helper.rb +386 -0
  9. data/app/helpers/admin/master_helper.rb +104 -0
  10. data/app/helpers/admin/public_helper.rb +27 -0
  11. data/app/helpers/admin/sidebar_helper.rb +236 -0
  12. data/app/helpers/admin/table_helper.rb +227 -0
  13. data/app/helpers/typus_helper.rb +194 -0
  14. data/app/models/typus_mailer.rb +14 -0
  15. data/app/models/typus_user.rb +5 -0
  16. data/app/views/admin/dashboard/_sidebar.html.erb +9 -0
  17. data/app/views/admin/resources/edit.html.erb +24 -0
  18. data/app/views/admin/resources/index.html.erb +23 -0
  19. data/app/views/admin/resources/new.html.erb +22 -0
  20. data/app/views/admin/resources/show.html.erb +18 -0
  21. data/app/views/admin/shared/_footer.html.erb +1 -0
  22. data/app/views/admin/shared/_pagination.html.erb +28 -0
  23. data/app/views/layouts/admin.html.erb +73 -0
  24. data/app/views/layouts/typus.html.erb +29 -0
  25. data/app/views/typus/dashboard.html.erb +9 -0
  26. data/app/views/typus/recover_password.html.erb +7 -0
  27. data/app/views/typus/reset_password.html.erb +15 -0
  28. data/app/views/typus/sign_in.html.erb +9 -0
  29. data/app/views/typus/sign_up.html.erb +7 -0
  30. data/app/views/typus_mailer/reset_password_link.erb +11 -0
  31. data/config/locales/typus/de.yml +109 -0
  32. data/config/locales/typus/es.yml +109 -0
  33. data/config/locales/typus/language.yml.template +113 -0
  34. data/config/locales/typus/pt-BR.yml +111 -0
  35. data/config/locales/typus/ru.yml +111 -0
  36. data/generators/typus/templates/config/initializers/typus.rb +33 -0
  37. data/generators/typus/templates/config/typus/README +51 -0
  38. data/generators/typus/templates/config/typus/application.yml +6 -0
  39. data/generators/typus/templates/config/typus/application_roles.yml +23 -0
  40. data/generators/typus/templates/config/typus/typus.yml +14 -0
  41. data/generators/typus/templates/config/typus/typus_roles.yml +2 -0
  42. data/generators/typus/templates/db/create_typus_users.rb +21 -0
  43. data/generators/typus/templates/public/images/admin/arrow_down.gif +0 -0
  44. data/generators/typus/templates/public/images/admin/arrow_up.gif +0 -0
  45. data/generators/typus/templates/public/images/admin/spinner.gif +0 -0
  46. data/generators/typus/templates/public/images/admin/status_false.gif +0 -0
  47. data/generators/typus/templates/public/images/admin/status_true.gif +0 -0
  48. data/generators/typus/templates/public/images/admin/trash.gif +0 -0
  49. data/generators/typus/templates/public/javascripts/admin/application.js +14 -0
  50. data/generators/typus/templates/public/stylesheets/admin/reset.css +68 -0
  51. data/generators/typus/templates/public/stylesheets/admin/screen.css +729 -0
  52. data/generators/typus/typus_generator.rb +122 -0
  53. data/generators/typus_update_schema_to_01/templates/config/typus.yml +14 -0
  54. data/generators/typus_update_schema_to_01/templates/migration.rb +11 -0
  55. data/generators/typus_update_schema_to_01/typus_update_schema_to_01_generator.rb +19 -0
  56. data/lib/typus.rb +122 -0
  57. data/lib/typus/active_record.rb +307 -0
  58. data/lib/typus/authentication.rb +142 -0
  59. data/lib/typus/configuration.rb +85 -0
  60. data/lib/typus/extensions/routes.rb +15 -0
  61. data/lib/typus/format.rb +55 -0
  62. data/lib/typus/generator.rb +81 -0
  63. data/lib/typus/hash.rb +8 -0
  64. data/lib/typus/locale.rb +17 -0
  65. data/lib/typus/object.rb +21 -0
  66. data/lib/typus/quick_edit.rb +40 -0
  67. data/lib/typus/reloader.rb +15 -0
  68. data/lib/typus/string.rb +11 -0
  69. data/lib/typus/templates/index.html.erb +11 -0
  70. data/lib/typus/templates/resource_controller.rb.erb +15 -0
  71. data/lib/typus/templates/resource_controller_test.rb.erb +10 -0
  72. data/lib/typus/templates/resources_controller.rb.erb +37 -0
  73. data/lib/typus/user.rb +134 -0
  74. data/lib/vendor/active_record.rb +15 -0
  75. data/lib/vendor/paginator.rb +143 -0
  76. data/rails/init.rb +3 -0
  77. data/tasks/typus_tasks.rake +32 -0
  78. data/test/config/broken/application.yml +68 -0
  79. data/test/config/broken/application_roles.yml +20 -0
  80. data/test/config/broken/empty.yml +0 -0
  81. data/test/config/broken/empty_roles.yml +0 -0
  82. data/test/config/broken/undefined.yml +3 -0
  83. data/test/config/broken/undefined_roles.yml +6 -0
  84. data/test/config/default/typus.yml +14 -0
  85. data/test/config/default/typus_roles.yml +2 -0
  86. data/test/config/empty/empty_01.yml +0 -0
  87. data/test/config/empty/empty_01_roles.yml +0 -0
  88. data/test/config/empty/empty_02.yml +0 -0
  89. data/test/config/empty/empty_02_roles.yml +0 -0
  90. data/test/config/locales/es.yml +10 -0
  91. data/test/config/ordered/001_roles.yml +2 -0
  92. data/test/config/ordered/002_roles.yml +2 -0
  93. data/test/config/unordered/app_one_roles.yml +2 -0
  94. data/test/config/unordered/app_two_roles.yml +2 -0
  95. data/test/config/working/application.yml +68 -0
  96. data/test/config/working/application_roles.yml +22 -0
  97. data/test/config/working/typus.yml +14 -0
  98. data/test/config/working/typus_roles.yml +2 -0
  99. data/test/fixtures/app/controllers/admin/assets_controller.rb +2 -0
  100. data/test/fixtures/app/controllers/admin/categories_controller.rb +2 -0
  101. data/test/fixtures/app/controllers/admin/comments_controller.rb +2 -0
  102. data/test/fixtures/app/controllers/admin/pages_controller.rb +2 -0
  103. data/test/fixtures/app/controllers/admin/posts_controller.rb +2 -0
  104. data/test/fixtures/app/controllers/admin/status_controller.rb +6 -0
  105. data/test/fixtures/app/controllers/admin/typus_users_controller.rb +2 -0
  106. data/test/fixtures/app/controllers/admin/watch_dog_controller.rb +6 -0
  107. data/test/fixtures/app/views/admin/comments/_edit.html.erb +1 -0
  108. data/test/fixtures/app/views/admin/comments/_index.html.erb +1 -0
  109. data/test/fixtures/app/views/admin/comments/_new.html.erb +1 -0
  110. data/test/fixtures/app/views/admin/comments/_show.html.erb +1 -0
  111. data/test/fixtures/app/views/admin/comments/_sidebar.html.erb +1 -0
  112. data/test/fixtures/app/views/admin/dashboard/_content.html.erb +1 -0
  113. data/test/fixtures/app/views/admin/dashboard/_sidebar.html.erb +1 -0
  114. data/test/fixtures/app/views/admin/resources/_sidebar.html.erb +1 -0
  115. data/test/fixtures/app/views/admin/shared/_footer.html.erb +1 -0
  116. data/test/fixtures/app/views/admin/status/index.html.erb +1 -0
  117. data/test/fixtures/app/views/admin/templates/_datepicker.html.erb +1 -0
  118. data/test/fixtures/assets.yml +11 -0
  119. data/test/fixtures/categories.yml +14 -0
  120. data/test/fixtures/comments.yml +27 -0
  121. data/test/fixtures/pages.yml +41 -0
  122. data/test/fixtures/posts.yml +37 -0
  123. data/test/fixtures/typus_users.yml +54 -0
  124. data/test/functional/admin/assets_controller_test.rb +57 -0
  125. data/test/functional/admin/categories_controller_test.rb +106 -0
  126. data/test/functional/admin/comments_controller_test.rb +120 -0
  127. data/test/functional/admin/master_controller_test.rb +5 -0
  128. data/test/functional/admin/posts_controller_test.rb +261 -0
  129. data/test/functional/admin/status_controller_test.rb +43 -0
  130. data/test/functional/admin/typus_users_controller_test.rb +239 -0
  131. data/test/functional/typus_controller_test.rb +321 -0
  132. data/test/helper.rb +51 -0
  133. data/test/helpers/admin/form_helper_test.rb +337 -0
  134. data/test/helpers/admin/master_helper_test.rb +69 -0
  135. data/test/helpers/admin/public_helper_test.rb +26 -0
  136. data/test/helpers/admin/sidebar_helper_test.rb +335 -0
  137. data/test/helpers/admin/table_helper_test.rb +239 -0
  138. data/test/helpers/typus_helper_test.rb +117 -0
  139. data/test/lib/active_record_test.rb +382 -0
  140. data/test/lib/configuration_test.rb +94 -0
  141. data/test/lib/hash_test.rb +11 -0
  142. data/test/lib/routes_test.rb +71 -0
  143. data/test/lib/string_test.rb +25 -0
  144. data/test/lib/typus_test.rb +85 -0
  145. data/test/models.rb +51 -0
  146. data/test/schema.rb +64 -0
  147. data/test/unit/typus_mailer_test.rb +33 -0
  148. data/test/unit/typus_test.rb +17 -0
  149. data/test/unit/typus_user_roles_test.rb +90 -0
  150. data/test/unit/typus_user_test.rb +177 -0
  151. data/test/vendor/active_record_test.rb +18 -0
  152. data/test/vendor/paginator_test.rb +136 -0
  153. data/typus.gemspec +228 -0
  154. metadata +241 -0
@@ -0,0 +1,142 @@
1
+ module Typus
2
+
3
+ module Authentication
4
+
5
+ protected
6
+
7
+ # Require login checks if the user is logged on Typus, otherwise
8
+ # is sent to the sign in page with a :back_to param to return where
9
+ # she tried to go.
10
+ def require_login
11
+
12
+ # Uncomment the following line for demo purpouses.
13
+ # session[:typus_user_id] = Typus.user_class.find(:first)
14
+
15
+ if session[:typus_user_id]
16
+ set_current_user
17
+ else
18
+ back_to = (request.env['REQUEST_URI'] == '/admin') ? nil : request.env['REQUEST_URI']
19
+ redirect_to admin_sign_in_path(:back_to => back_to)
20
+ end
21
+
22
+ end
23
+
24
+ # Return the current user. If role does not longer exist on the
25
+ # system @current_user will be signed out from Typus.
26
+ def set_current_user
27
+
28
+ @current_user = Typus.user_class.find(session[:typus_user_id])
29
+
30
+ unless @current_user.respond_to?(:role)
31
+ raise _("Run 'script/generate typus_update_schema_to_01 -f && rake db:migrate' to update database schema.")
32
+ end
33
+
34
+ unless Typus::Configuration.roles.keys.include?(@current_user.role)
35
+ raise _("Role does no longer exists.")
36
+ end
37
+
38
+ unless @current_user.status
39
+ back_to = (request.env['REQUEST_URI'] == '/admin') ? nil : request.env['REQUEST_URI']
40
+ raise _("Typus user has been disabled.")
41
+ end
42
+
43
+ rescue Exception => error
44
+ flash[:notice] = error.message
45
+ session[:typus_user_id] = nil
46
+ redirect_to admin_sign_in_path(:back_to => back_to)
47
+ end
48
+
49
+ # Action is available on: edit, update, toggle and destroy
50
+ def check_if_user_can_perform_action_on_user
51
+
52
+ return unless @item.kind_of?(Typus.user_class)
53
+
54
+ current_user = (@current_user == @item)
55
+
56
+ message = case params[:action]
57
+ when 'edit'
58
+
59
+ # Only admin and owner of Typus User can edit.
60
+ if !@current_user.is_root? && !current_user
61
+ _("As you're not the admin or the owner of this record you cannot edit it.")
62
+ end
63
+
64
+ when 'update'
65
+
66
+ # current_user cannot change her role.
67
+ if current_user && !(@item.role == params[:item][:role])
68
+ _("You can't change your role.")
69
+ end
70
+
71
+ when 'toggle'
72
+
73
+ # Only admin can toggle typus user status, but not herself.
74
+ if @current_user.is_root? && current_user
75
+ _("You can't toggle your status.")
76
+ elsif !@current_user.is_root?
77
+ _("You're not allowed to toggle status.")
78
+ end
79
+
80
+ when 'destroy'
81
+
82
+ # Admin can remove anything except herself.
83
+ if @current_user.is_root? && current_user
84
+ _("You can't remove yourself.")
85
+ elsif !@current_user.is_root?
86
+ _("You're not allowed to remove Typus Users.")
87
+ end
88
+
89
+ end
90
+
91
+ if message
92
+ flash[:notice] = message
93
+ redirect_to :back rescue redirect_to admin_dashboard_path
94
+ end
95
+
96
+ end
97
+
98
+ # This method checks if the user can perform the requested action.
99
+ # It works on models, so its available on the admin_controller.
100
+ def check_if_user_can_perform_action_on_resource
101
+
102
+ message = case params[:action]
103
+ when 'index', 'show'
104
+ _("{{current_user_role}} can't display items.",
105
+ :current_user_role => @current_user.role.capitalize)
106
+ when 'edit', 'update', 'position', 'toggle', 'relate', 'unrelate'
107
+ when 'destroy'
108
+ _("{{current_user_role}} can't delete this item.",
109
+ :current_user_role => @current_user.role.capitalize)
110
+ else
111
+ _("{{current_user_role}} can't perform action ({{action}}).",
112
+ :current_user_role => @current_user.role.capitalize,
113
+ :action => params[:action])
114
+ end
115
+
116
+ unless @current_user.can_perform?(@resource[:class], params[:action])
117
+ flash[:notice] = message || _("{{current_user_role}} can't perform action. ({{action}}).",
118
+ :current_user_role => @current_user.role.capitalize,
119
+ :action => params[:action])
120
+ redirect_to :back rescue redirect_to admin_dashboard_path
121
+ end
122
+
123
+ end
124
+
125
+ # This method checks if the user can perform the requested action.
126
+ # It works on resources, which are not models, so its available on
127
+ # the typus_controller.
128
+ def check_if_user_can_perform_action_on_resource_without_model
129
+ controller = params[:controller].split('/').last
130
+ action = params[:action]
131
+ unless @current_user.can_perform?(controller.camelize, action, { :special => true })
132
+ flash[:notice] = _("{{current_user_role}} can't go to {{action}} on {{controller}}.",
133
+ :current_user_role => @current_user.role.capitalize,
134
+ :action => action,
135
+ :controller => controller.humanize.downcase)
136
+ redirect_to :back rescue redirect_to admin_dashboard_path
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,85 @@
1
+ module Typus
2
+
3
+ module Configuration
4
+
5
+ # Default options which can be overwritten from the initializer.
6
+ typus_options = { :app_name => 'Typus',
7
+ :config_folder => 'config/typus',
8
+ :email => 'admin@example.com',
9
+ :locales => [ [ "English", :en ] ],
10
+ :recover_password => false,
11
+ :root => 'admin',
12
+ :ssl => false,
13
+ :templates_folder => 'admin/templates',
14
+ :user_class_name => 'TypusUser',
15
+ :user_fk => 'typus_user_id' }
16
+
17
+ # Default options which can be overwritten from the initializer.
18
+ model_options = { :default_action_on_item => 'edit',
19
+ :end_year => nil,
20
+ :form_rows => 10,
21
+ :icon_on_boolean => true,
22
+ :index_after_save => false,
23
+ :minute_step => 5,
24
+ :nil => 'nil',
25
+ :on_header => false,
26
+ :only_user_items => false,
27
+ :per_page => 15,
28
+ :sidebar_selector => 5,
29
+ :start_year => nil,
30
+ :tiny_mce => { :theme => 'advanced',
31
+ :theme_advanced_toolbar_location => 'top',
32
+ :theme_advanced_toolbar_align => 'left' },
33
+ :toggle => true }
34
+
35
+ @@options = typus_options.merge(model_options)
36
+
37
+ mattr_accessor :options
38
+
39
+ # Read Typus Configuration files placed on <tt>config/typus/**/*.yml</tt>.
40
+ def self.config!
41
+
42
+ files = Dir["#{Rails.root}/#{options[:config_folder]}/**/*.yml"].sort
43
+ files = files.delete_if { |x| x.include?('_roles.yml') }
44
+
45
+ @@config = {}
46
+ files.each do |file|
47
+ data = YAML.load_file(file)
48
+ @@config = @@config.merge(data) if data
49
+ end
50
+
51
+ return @@config
52
+
53
+ end
54
+
55
+ mattr_accessor :config
56
+
57
+ # Read Typus Roles from configuration files placed on <tt>config/typus/**/*_roles.yml</tt>.
58
+ def self.roles!
59
+
60
+ files = Dir["#{Rails.root}/#{options[:config_folder]}/**/*_roles.yml"].sort
61
+
62
+ @@roles = { options[:root] => {} }
63
+
64
+ files.each do |file|
65
+ data = YAML.load_file(file)
66
+ next unless data
67
+ data.each do |key, value|
68
+ next unless value
69
+ begin
70
+ @@roles[key] = @@roles[key].merge(value)
71
+ rescue
72
+ @@roles[key] = value
73
+ end
74
+ end
75
+ end
76
+
77
+ return @@roles.compact
78
+
79
+ end
80
+
81
+ mattr_accessor :roles
82
+
83
+ end
84
+
85
+ end
@@ -0,0 +1,15 @@
1
+ if defined?(ActionController::Routing::RouteSet)
2
+
3
+ class ActionController::Routing::RouteSet
4
+
5
+ def load_routes_with_typus!
6
+ typus_routes = File.join(File.dirname(__FILE__), 'routes_hack.rb')
7
+ add_configuration_file(typus_routes) unless configuration_files.include?(typus_routes)
8
+ load_routes_without_typus!
9
+ end
10
+
11
+ alias_method_chain :load_routes!, :typus
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,55 @@
1
+ module Typus
2
+
3
+ module Format
4
+
5
+ protected
6
+
7
+ def generate_html
8
+
9
+ items_count = @resource[:class].count(:joins => @joins, :conditions => @conditions)
10
+ items_per_page = @resource[:class].typus_options_for(:per_page).to_i
11
+
12
+ @pager = ::Paginator.new(items_count, items_per_page) do |offset, per_page|
13
+ data(:limit => per_page, :offset => offset)
14
+ end
15
+
16
+ @items = @pager.page(params[:page])
17
+
18
+ select_template :index
19
+
20
+ end
21
+
22
+ def generate_csv
23
+
24
+ require 'fastercsv'
25
+
26
+ fields = @resource[:class].typus_fields_for(:csv).collect { |i| i.first }
27
+ csv_string = FasterCSV.generate do |csv|
28
+ csv << fields.map { |f| _(f.humanize) }
29
+ data.each { |i| csv << fields.map { |f| i.send(f) } }
30
+ end
31
+
32
+ filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}_#{@resource[:self]}.csv"
33
+ send_data(csv_string,
34
+ :type => 'text/csv; charset=utf-8; header=present',
35
+ :filename => filename)
36
+
37
+ rescue LoadError
38
+ render :text => _("FasterCSV is not installed.")
39
+ end
40
+
41
+ def generate_xml
42
+ fields = @resource[:class].typus_fields_for(:xml).collect { |i| i.first }
43
+ render :xml => data.to_xml(:only => fields)
44
+ end
45
+
46
+ def data(*args)
47
+ eager_loading = @resource[:class].reflect_on_all_associations(:belongs_to).map { |i| i.name }
48
+ options = { :joins => @joins, :conditions => @conditions, :order => @order, :include => eager_loading }
49
+ options.merge!(args.extract_options!)
50
+ @resource[:class].find(:all, options)
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,81 @@
1
+ require 'ftools'
2
+
3
+ module Typus
4
+
5
+ def self.generator
6
+
7
+ # Create app/controllers/admin if doesn't exist.
8
+ admin_controllers_folder = "#{Rails.root}/app/controllers/admin"
9
+ Dir.mkdir(admin_controllers_folder) unless File.directory?(admin_controllers_folder)
10
+
11
+ # Get a list of controllers under `app/controllers/admin`.
12
+ admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{admin_controllers_folder}/*.rb"]
13
+ admin_controllers = admin_controllers.map { |i| File.basename(i) }
14
+
15
+ # Create app/views/admin if doesn't exist.
16
+ admin_views_folder = "#{Rails.root}/app/views/admin"
17
+ Dir.mkdir(admin_views_folder) unless File.directory?(admin_views_folder)
18
+
19
+ # Create test/functional/admin if doesn't exist.
20
+ admin_controller_tests_folder = "#{Rails.root}/test/functional/admin"
21
+ if File.directory?("#{Rails.root}/test")
22
+ Dir.mkdir(admin_controller_tests_folder) unless File.directory?(admin_controller_tests_folder)
23
+ end
24
+
25
+ # Get a list of functional tests under `test/functional/admin`.
26
+ admin_controller_tests = Dir["#{admin_controller_tests_folder}/*.rb"]
27
+ admin_controller_tests = admin_controller_tests.map { |i| File.basename(i) }
28
+
29
+ # Generate controllers for tableless models.
30
+ resources.each do |resource|
31
+
32
+ controller_filename = "#{resource.underscore}_controller.rb"
33
+ controller_location = "#{admin_controllers_folder}/#{controller_filename}"
34
+
35
+ if !admin_controllers.include?(controller_filename)
36
+ template = File.read("#{File.dirname(__FILE__)}/templates/resource_controller.rb.erb")
37
+ content = ERB.new(template).result(binding)
38
+ File.open(controller_location, "w+") { |f| f << content }
39
+ end
40
+
41
+ # And now we create the view.
42
+ view_folder = "#{admin_views_folder}/#{resource.underscore}"
43
+ view_filename = "index.html.erb"
44
+
45
+ if !File.exist?("#{view_folder}/#{view_filename}")
46
+ Dir.mkdir(view_folder) unless File.directory?(view_folder)
47
+ origin = "#{File.dirname(__FILE__)}/templates/index.html.erb"
48
+ destination = "#{view_folder}/#{view_filename}"
49
+ File.copy(origin, destination)
50
+ end
51
+
52
+ end
53
+
54
+ # Generate:
55
+ # `app/controllers/admin/#{resource}_controller.rb`
56
+ # `test/functional/admin/#{resource}_controller_test.rb`
57
+ models.each do |model|
58
+
59
+ controller_filename = "#{model.tableize}_controller.rb"
60
+ controller_location = "#{admin_controllers_folder}/#{controller_filename}"
61
+
62
+ if !admin_controllers.include?(controller_filename)
63
+ template = File.read("#{File.dirname(__FILE__)}/templates/resources_controller.rb.erb")
64
+ content = ERB.new(template).result(binding)
65
+ File.open(controller_location, "w+") { |f| f << content }
66
+ end
67
+
68
+ test_filename = "#{model.tableize}_controller_test.rb"
69
+ test_location = "#{admin_controller_tests_folder}/#{test_filename}"
70
+
71
+ if !admin_controller_tests.include?(test_filename) && File.directory?("#{Rails.root}/test")
72
+ template = File.read("#{File.dirname(__FILE__)}/templates/resource_controller_test.rb.erb")
73
+ content = ERB.new(template).result(binding)
74
+ File.open(test_location, "w+") { |f| f << content }
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
81
+ end
data/lib/typus/hash.rb ADDED
@@ -0,0 +1,8 @@
1
+ class Hash
2
+
3
+ # Remove nil and empty keys.
4
+ def compact
5
+ delete_if { |key, value| value.nil? || value.empty? }
6
+ end
7
+
8
+ end
@@ -0,0 +1,17 @@
1
+ module Typus
2
+
3
+ module Locale
4
+
5
+ def set_locale
6
+ if params[:locale]
7
+ I18n.locale = params[:locale]
8
+ session[:typus_locale] = params[:locale]
9
+ redirect_to :back
10
+ else
11
+ I18n.locale = session[:typus_locale] || Typus.default_locale
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,21 @@
1
+ class Object
2
+
3
+ # Instead of having to translate strings and defining a default value:
4
+ #
5
+ # t("Hello World!", :default => 'Hello World!')
6
+ #
7
+ # We define this method to define the value only once:
8
+ #
9
+ # _("Hello World!")
10
+ #
11
+ # Note that interpolation still works ...
12
+ #
13
+ # _("Hello {{world}}!", :world => @world)
14
+ #
15
+ def _(msg, *args)
16
+ options = args.extract_options!
17
+ options[:default] = msg
18
+ I18n.t(msg, options)
19
+ end
20
+
21
+ end
@@ -0,0 +1,40 @@
1
+ module Typus
2
+
3
+ module QuickEdit
4
+
5
+ def quick_edit
6
+
7
+ render :text => '' and return unless session[:typus_user_id]
8
+
9
+ links = [[ "Dashboard", admin_dashboard_path ]]
10
+ links << [ params[:message], "/admin/#{params[:path]}" ] if params[:message] && params[:path]
11
+
12
+ options = links.reverse.map do |link|
13
+ "<li><a href=\"#{link.last}\">#{link.first}</a></li>"
14
+ end
15
+
16
+ content = <<-HTML
17
+ var links = '';
18
+ links += '<div id="quick_edit">';
19
+ links += '<ul>';
20
+ links += '#{options}';
21
+ links += '</ul>';
22
+ links += '</div>';
23
+ links += '<style type="text/css">';
24
+ links += '<!--';
25
+ links += '#quick_edit { font-size: 12px; font-family: sans-serif; position: absolute; top: 0px; right: 0px; margin: 10px; }';
26
+ links += '#quick_edit a { color: #FFF; font-weight: bold; text-decoration: none; }'
27
+ links += '#quick_edit ul { margin: 0; padding: 0; }';
28
+ links += '#quick_edit li { display: inline; background: #000; margin: 0 0 0 5px; padding: 3px 5px; }';
29
+ links += '-->';
30
+ links += '</style>';
31
+ document.write(links);
32
+ HTML
33
+
34
+ render :text => content
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end