typus 3.1.0.rc11 → 3.1.0.rc12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +4 -16
  2. data/.gitmodules +3 -6
  3. data/README.md +50 -16
  4. data/Rakefile +19 -26
  5. data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +15 -18
  6. data/app/helpers/admin/resources/data_types/position_helper.rb +9 -11
  7. data/app/helpers/admin/resources/form_helper.rb +13 -13
  8. data/app/helpers/admin/resources/relationships_helper.rb +4 -1
  9. data/app/helpers/admin/resources/table_helper.rb +11 -14
  10. data/app/helpers/admin/resources_helper.rb +12 -3
  11. data/app/themes/default/assets/javascripts/typus/jquery.application.js +0 -6
  12. data/app/themes/default/assets/stylesheets/typus/pagination.css +1 -2
  13. data/app/themes/default/views/admin/base/user_guide.html.erb +25 -27
  14. data/app/themes/default/views/admin/dashboard/_applications.html.erb +2 -10
  15. data/app/themes/default/views/admin/dashboard/_sidebar.html.erb +9 -2
  16. data/app/themes/default/views/admin/dashboard/styles.html.erb +10 -15
  17. data/app/themes/default/views/admin/resources/_form.html.erb +4 -2
  18. data/app/themes/default/views/admin/resources/_form_javascripts.html.erb +0 -0
  19. data/app/themes/default/views/admin/templates/README.md +5 -0
  20. data/app/themes/default/views/admin/templates/_dragonfly.html.erb +1 -0
  21. data/app/themes/default/views/admin/templates/_has_one.html.erb +1 -1
  22. data/app/themes/default/views/admin/templates/_position.html.erb +5 -0
  23. data/app/themes/default/views/admin/templates/_profile_sidebar.html.erb +2 -1
  24. data/app/themes/default/views/admin/templates/_selector.html.erb +4 -1
  25. data/app/themes/default/views/admin/templates/_text_with_ckeditor.html.erb +0 -4
  26. data/app/themes/default/views/helpers/admin/resources/_filters.html.erb +1 -3
  27. data/app/themes/default/views/helpers/admin/resources/_sidebar.html.erb +6 -9
  28. data/app/themes/default/views/helpers/admin/resources/_table.html.erb +11 -13
  29. data/lib/generators/templates/config/initializers/typus_resources.rb +1 -1
  30. data/lib/generators/templates/config/typus/README +1 -1
  31. data/lib/typus.rb +15 -26
  32. data/lib/typus/authentication/base.rb +4 -0
  33. data/lib/typus/authentication/http_basic.rb +2 -2
  34. data/lib/typus/authentication/session.rb +3 -5
  35. data/lib/typus/configuration.rb +14 -12
  36. data/lib/typus/controller/filters.rb +22 -0
  37. data/lib/typus/i18n.rb +17 -0
  38. data/lib/typus/orm/active_record/user/class_methods.rb +1 -1
  39. data/lib/typus/orm/base.rb +2 -2
  40. data/lib/typus/resources.rb +1 -1
  41. data/lib/typus/version.rb +1 -1
  42. metadata +21 -26
  43. data/.yardopts +0 -6
  44. data/Gemfile +0 -60
  45. data/doc/yard/handlers/configurable_attr_handler.rb +0 -38
  46. data/doc/yard/setup.rb +0 -9
  47. data/doc/yard/templates/default/fulldoc/html/css/common.css +0 -109
  48. data/doc/yard/templates/default/layout/html/layout.erb +0 -126
  49. data/doc/yard/templates/default/module/html/configuration_summary.erb +0 -31
  50. data/doc/yard/templates/default/module/setup.rb +0 -17
@@ -8,20 +8,12 @@
8
8
  </tr>
9
9
  </thead>
10
10
 
11
- <% admin_user.application(app).each do |model| %>
12
-
13
- <%
14
- klass = model.typus_constantize
15
- klass_human_name = klass.model_name.human.pluralize
16
- admin_items_path = { :controller => "/admin/#{klass.to_resource}" }
17
- %>
18
-
11
+ <% admin_user.application(app).map { |i| i.typus_constantize }.each do |klass| %>
19
12
  <tr class="<%= cycle("even", "odd") %>">
20
13
  <td>
21
- <%= link_to klass_human_name, admin_items_path %>
14
+ <%= link_to klass.model_name.human.pluralize, :controller => "/admin/#{klass.to_resource}" %>
22
15
  </td>
23
16
  </tr>
24
-
25
17
  <% end %>
26
18
 
27
19
  </table>
@@ -1,5 +1,12 @@
1
1
  <h2>Welcome!</h2>
2
2
 
3
- <p>If you need help don't hesitate in joining the <%= link_to 'mailing list', 'http://groups.google.com/group/typus' %> or use the provided <%= link_to "user guide", admin_user_guide_path %>.</p>
3
+ <%
4
+ mailing_list = link_to('mailing list', 'http://groups.google.com/group/typus')
5
+ user_guide = link_to('user guide', admin_user_guide_path)
6
+ %>
4
7
 
5
- <p>Replace this sidebar dropping a file named <code>_sidebar.html.erb</code> on the <code>app/views/admin/dashboard</code> folder.</p>
8
+ <p>If you need help don't hesitate in joining the <%= mailing_list %> or use
9
+ the provided <%= user_guide %>.</p>
10
+
11
+ <p>Replace this sidebar dropping a file named <code>_sidebar.html.erb</code>
12
+ on the <code>app/views/admin/dashboard</code> folder.</p>
@@ -30,27 +30,22 @@
30
30
 
31
31
  <h2>Header (h2) <small>Small <a href="#">link</a></small></h2>
32
32
 
33
- <p>
34
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
33
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
35
34
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
36
35
  quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
37
36
  consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
38
37
  cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
39
- non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
40
- </p>
38
+ non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
41
39
 
42
40
  <blockquote>
43
- <p>
44
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
41
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
45
42
  tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
46
43
  quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
47
- consequat.
48
- </p>
49
- <p>
50
- Duis aute irure dolor in reprehenderit in voluptate velit esse
51
- cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
52
- non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
53
- </p>
44
+ consequat.</p>
45
+
46
+ <p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
47
+ dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
48
+ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
54
49
  </blockquote>
55
50
 
56
51
  <pre>
@@ -138,8 +133,8 @@ consequat.
138
133
 
139
134
  <div class="filters">
140
135
  <ul>
141
- <li>Filter</li>
142
- <li>Filter</li>
136
+ <li>Filter</li>
137
+ <li>Filter</li>
143
138
  </ul>
144
139
  </div>
145
140
 
@@ -1,6 +1,8 @@
1
+ <%= render "form_javascripts" %>
2
+
1
3
  <%= form_for @item, :url => options, :html => { :class => "resource", :multipart => true } do |form| %>
2
4
 
3
- <%= display_errors %>
5
+ <%= render "helpers/admin/resources/errors" %>
4
6
 
5
7
  <fieldset class="inputs">
6
8
  <ol>
@@ -10,7 +12,7 @@
10
12
 
11
13
  <fieldset class="buttons">
12
14
  <ol>
13
- <% save_options.each do |key, value| %>
15
+ <% build_save_options.each do |key, value| %>
14
16
  <li><%= submit_tag Typus::I18n.t(value), :name => key, :onclick => "setConfirmUnload(false);", :disable_with => Typus::I18n.t(value) %></li>
15
17
  <% end %>
16
18
  </ol>
@@ -0,0 +1,5 @@
1
+ Some snippets to use in the future:
2
+
3
+ <input type="hidden"
4
+ id="pageListJSON"
5
+ value="[<%= Page.all.map { |p| "['#{p.to_label}', '/pages/#{p.respond?(:permalink) p.permalink : p.id}']" }.join(", ") %>]">
@@ -1,5 +1,6 @@
1
1
  <li id="<%= attribute %>">
2
2
  <%= form.label attribute, link_to_detach_attribute_for_dragonfly(attribute) %>
3
3
  <%= form.file_field attribute, options %>
4
+ <%= form.hidden_field "retained_#{attribute}" %>
4
5
  <%= typus_dragonfly_preview(@item, attribute) %>
5
6
  </li>
@@ -1,7 +1,7 @@
1
1
  <div class="box_relationships" id="<%= association_name %>">
2
2
 
3
3
  <h2>
4
- <%= association_name.humanize %>
4
+ <%= association_name.titleize.humanize %>
5
5
  <small><%= add_new %></small>
6
6
  </h2>
7
7
 
@@ -0,0 +1,5 @@
1
+ <%= item.position %>
2
+
3
+ <div class="actions">
4
+ <%= html_position.join(connector).html_safe %>
5
+ </div>
@@ -1,3 +1,4 @@
1
1
  <h2>Profile</h2>
2
2
 
3
- <p>Replace this sidebar dropping a file named <code>_profile_sidebar.html.erb</code> on <code>app/views/admin/templates</code> folder.</p>
3
+ <p>Replace this sidebar dropping a file named <code>_profile_sidebar.html.erb</code>
4
+ on <code>app/views/admin/templates</code> folder.</p>
@@ -1,4 +1,7 @@
1
1
  <%
2
+ custom = { :include_blank => true }
3
+ options.merge!(custom)
4
+
2
5
  if @resource.typus_field_options_for(:read_only).include?(attribute.to_sym)
3
6
  html_options.merge!(:disabled => 'disabled')
4
7
  message = Typus::I18n.t("Read only")
@@ -7,5 +10,5 @@
7
10
 
8
11
  <li id="<%= attribute %>">
9
12
  <%= form.label attribute, "#{label_text} <small>#{message}</small>".html_safe %>
10
- <%= form.select attribute, @resource.send(attribute), options.merge!(:include_blank => true), html_options %>
13
+ <%= form.select attribute, @resource.send(attribute), options, html_options %>
11
14
  </li>
@@ -7,10 +7,6 @@
7
7
  options = options.merge!(custom)
8
8
  %>
9
9
 
10
- <input type="hidden"
11
- id="pageListJSON"
12
- value="[<%= Page.all.map { |p| "['#{p.to_label}', '/pages/#{p.respond?(:permalink) p.permalink : p.id}']" }.join(", ") %>]">
13
-
14
10
  <li id="<%= attribute %>">
15
11
  <%= form.label attribute, label_text %>
16
12
  <%= form.text_area attribute, options %>
@@ -10,9 +10,7 @@
10
10
  <%= hidden_field_tag key, value %>
11
11
  <% end %>
12
12
 
13
- <li><%= submit_tag Typus::I18n.t("Filter"),
14
- :name => nil,
15
- :disable_with => Typus::I18n.t("Sending data ...") %></li>
13
+ <li><%= submit_tag Typus::I18n.t("Filter"), :name => nil, :disable_with => Typus::I18n.t("Sending data ...") %></li>
16
14
  </ul>
17
15
  </div>
18
16
 
@@ -1,18 +1,15 @@
1
- <% resources.each do |key, value| %>
1
+ <% resources.each do |resource, actions| %>
2
2
 
3
- <%
4
- klass = key.typus_constantize
5
- resource = "/admin/#{klass.to_resource}"
6
- %>
3
+ <% klass = resource.typus_constantize %>
7
4
 
8
- <%= link_to :controller => resource, :action => "index" do %>
5
+ <%= link_to :controller => "/admin/#{klass.to_resource}" do %>
9
6
  <h3><%= klass.model_name.human.pluralize %></h3>
10
7
  <% end %>
11
8
 
12
- <% if @resource.model_name.eql?(key) %>
9
+ <% if @resource.model_name.eql?(resource) %>
13
10
  <ul>
14
- <% value.each do |v| %>
15
- <li><%= v %></li>
11
+ <% actions.each do |action| %>
12
+ <li><%= link_to action[:message], action[:url] %></li>
16
13
  <% end %>
17
14
  </ul>
18
15
  <% end %>
@@ -1,5 +1,4 @@
1
- <table>
2
-
1
+ <% content_for :table_headers do %>
3
2
  <thead>
4
3
  <tr>
5
4
  <% if controller.respond_to?(:bulk) %>
@@ -10,6 +9,11 @@
10
9
  <% end %>
11
10
  </tr>
12
11
  </thead>
12
+ <% end %>
13
+
14
+ <table>
15
+
16
+ <%= yield :table_headers %>
13
17
 
14
18
  <% items.each do |item| %>
15
19
  <tr class="<%= cycle('even', 'odd') %>" id="<%= dom_id(item) %>">
@@ -23,7 +27,10 @@
23
27
  <%= field %>
24
28
  <% if index.zero? %>
25
29
  <div class="actions">
26
- <%= table_actions(model, item, association_name) %>
30
+ <% table_actions(model, item, association_name).each_with_index do |action, index| %>
31
+ <%= "/" unless index.zero? %>
32
+ <%= link_to action[:message], action[:url], action[:options] %>
33
+ <% end %>
27
34
  </div>
28
35
  <% end %>
29
36
  </td>
@@ -31,15 +38,6 @@
31
38
  </tr>
32
39
  <% end %>
33
40
 
34
- <thead>
35
- <tr>
36
- <% if controller.respond_to?(:bulk) %>
37
- <th><%= check_box_tag "action-toggle", "", false, :class => "action-toggle" %></th>
38
- <% end %>
39
- <% headers.each do |header| %>
40
- <th><%= header %></th>
41
- <% end %>
42
- </tr>
43
- </thead>
41
+ <%= yield :table_headers %>
44
42
 
45
43
  </table>
@@ -16,7 +16,7 @@ Typus::Resources.setup do |config|
16
16
  # config.only_user_items = false
17
17
 
18
18
  # Defines per_page.
19
- # config.per_page = 15
19
+ # config.per_page = 25
20
20
 
21
21
  # Defines start_year.
22
22
  # config.start_year = nil
@@ -39,7 +39,7 @@ most common settings.
39
39
  minute_step: 15
40
40
  nil: 'nil'
41
41
  only_user_items: true
42
- per_page: 5
42
+ per_page: 25
43
43
  start_year: 1990
44
44
 
45
45
  Note: To define namespace models use :: as a separator. (i.e. Delayed::Job)
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "support/active_record"
4
2
  require "support/hash"
5
3
  require "support/object"
@@ -72,10 +70,19 @@ module Typus
72
70
  ##
73
71
  # Pagination options passed to Kaminari helper.
74
72
  #
73
+ # :previous_label => "&larr; " + Typus::I18n.t("Previous")
74
+ # :next_label => Typus::I18n.t("Next") + " &rarr;"
75
+ #
76
+ # Note that `Kaminari` only accepts the following configuration options:
77
+ #
78
+ # - default_per_page (25 by default)
79
+ # - window (4 by default)
80
+ # - outer_window (0 by default)
81
+ # - left (0 by default)
82
+ # - right (0 by default)
83
+ #
75
84
  mattr_accessor :pagination
76
- @@pagination = { :window => 0,
77
- :previous_label => "&larr; " + Typus::I18n.t("Previous"),
78
- :next_label => Typus::I18n.t("Next") + " &rarr;" }
85
+ @@pagination = { :window => 0 }
79
86
 
80
87
  ##
81
88
  # Define a password.
@@ -147,14 +154,11 @@ module Typus
147
154
 
148
155
  # Lists models from the configuration file.
149
156
  def models
150
- if config = Typus::Configuration.config
151
- config.map { |i| i.first }.sort
152
- else
153
- []
154
- end
157
+ Typus::Configuration.config.map { |i| i.first }.sort
155
158
  end
156
159
 
157
- # Lists resources, which are tableless models.
160
+ # Lists resources, which are tableless models. This is done by looking at
161
+ # the roles, which handle the permissions for this kind of data.
158
162
  def resources
159
163
  if roles = Typus::Configuration.roles
160
164
  roles.keys.map do |key|
@@ -171,21 +175,6 @@ module Typus
171
175
  Dir.chdir(model_dir) { Dir["**/*.rb"] }
172
176
  end
173
177
 
174
- def locales
175
- { "Català" => "ca",
176
- "German" => "de",
177
- "Greek" => "el",
178
- "English" => "en",
179
- "Español" => "es",
180
- "Français" => "fr",
181
- "Magyar" => "hu",
182
- "Italiano" => "It",
183
- "Portuguese" => "pt-PT",
184
- "Brazilian Portuguese" => "pt-BR",
185
- "Russian" => "ru",
186
- "中文" => "zh-CN" }
187
- end
188
-
189
178
  def application_models
190
179
  detect_application_models.map do |model|
191
180
  class_name = model.sub(/\.rb$/,"").camelize
@@ -15,6 +15,10 @@ module Typus
15
15
  def set_attributes_on_create; end
16
16
  def set_attributes_on_update; end
17
17
 
18
+ def not_allowed
19
+ render :text => "Not allowed!", :status => :unprocessable_entity
20
+ end
21
+
18
22
  end
19
23
  end
20
24
  end
@@ -8,8 +8,8 @@ module Typus
8
8
 
9
9
  def authenticate
10
10
  @admin_user = FakeUser.new
11
- authenticate_or_request_with_http_basic(Typus.admin_title) do |user_name, password|
12
- user_name == Typus.username && password == Typus.password
11
+ authenticate_or_request_with_http_basic(Typus.admin_title) do |username, password|
12
+ username == Typus.username && password == Typus.password
13
13
  end
14
14
  end
15
15
 
@@ -59,7 +59,9 @@ module Typus
59
59
  # Admin can update himself except setting the status to false!. Other
60
60
  # users can update their profile as the attributes (role & status)
61
61
  # are protected.
62
- status_changed = !(@item.status == params[@object_name][:status])
62
+ status_as_boolean = params[@object_name][:status] == "1" ? true : false
63
+
64
+ status_changed = !(@item.status == status_as_boolean)
63
65
  role_changed = !(@item.role == params[@object_name][:role])
64
66
 
65
67
  root_changed_his_status_or_role = current_user_is_root && (status_changed || role_changed)
@@ -78,10 +80,6 @@ module Typus
78
80
  not_allowed if admin_user.cannot?(params[:action], resource, { :special => true })
79
81
  end
80
82
 
81
- def not_allowed
82
- render :text => "Not allowed!", :status => :unprocessable_entity
83
- end
84
-
85
83
  #--
86
84
  # If item is owned by another user, we only can perform a show action on
87
85
  # the item. Updated item is also blocked.
@@ -1,11 +1,9 @@
1
1
  module Typus
2
2
  module Configuration
3
3
 
4
- # Read configuration from <tt>config/typus/**/*.yml</tt>.
4
+ # Read configuration from <tt>config/typus/*.yml</tt>.
5
5
  def self.config!
6
- application = Dir[File.join(Typus.config_folder, "**", "*.yml").to_s]
7
- plugins = Dir[File.join("vendor", "plugins", "*", "config", "typus", "*.yml").to_s]
8
- files = (application + plugins).reject { |f| f.include?("_roles.yml") }
6
+ files = Dir[File.join(Typus.config_folder, "*.yml").to_s].reject { |f| f.match(/_roles.yml/) }
9
7
 
10
8
  @@config = {}
11
9
 
@@ -14,17 +12,18 @@ module Typus
14
12
  @@config.merge!(data)
15
13
  end
16
14
  end
17
-
18
- @@config
19
15
  end
20
16
 
21
17
  mattr_accessor :config
18
+ @@config = {}
19
+
20
+ def self.register_config(config)
21
+ @@config.merge!(config)
22
+ end
22
23
 
23
- # Read roles from files <tt>config/typus/**/*_roles.yml</tt>.
24
+ # Read roles from files <tt>config/typus/*_roles.yml</tt>.
24
25
  def self.roles!
25
- application = Dir[File.join(Typus.config_folder, "**", "*_roles.yml").to_s]
26
- plugins = Dir[File.join("vendor", "plugins", "*", "config", "typus", "*_roles.yml").to_s]
27
- files = (application + plugins).sort
26
+ files = Dir[File.join(Typus.config_folder, "*_roles.yml").to_s].sort
28
27
 
29
28
  @@roles = {}
30
29
 
@@ -35,11 +34,14 @@ module Typus
35
34
  end
36
35
  end
37
36
  end
38
-
39
- @@roles
40
37
  end
41
38
 
42
39
  mattr_accessor :roles
40
+ @@roles = {}
41
+
42
+ def self.register_roles(roles)
43
+ @@roles.merge!(roles)
44
+ end
43
45
 
44
46
  def self.models_constantized!
45
47
  @@models_constantized = config.map { |i| i.first }.inject({}) { |result, model| result[model] = model.constantize; result }