typus 3.1.0.rc17 → 3.1.0.rc18

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -32,7 +32,7 @@ Add **Typus** to your `Gemfile`
32
32
  gem 'typus', '~> 3.1.0.rc'
33
33
 
34
34
  # Bundle edge typus instead:
35
- # gem 'typus', :git => 'git://github.com/typus/typus.git', :branch => '3-1-unstable'
35
+ # gem 'typus', :git => 'git://github.com/typus/typus.git'
36
36
 
37
37
  Update your bundle, run the generator and start the application server:
38
38
 
data/Rakefile CHANGED
@@ -22,15 +22,8 @@ RDoc::Task.new do |rdoc|
22
22
  rdoc.rdoc_files.include('lib/**/*.rb')
23
23
  end
24
24
 
25
- RUBIES = %w[1.8.7 ree 1.9.2 jruby].join(",")
26
-
27
25
  namespace :setup do
28
26
 
29
- desc "Setup test environment"
30
- task :test_environment do
31
- system "rvm install #{RUBIES}"
32
- end
33
-
34
27
  desc "Setup CI Joe"
35
28
  task :cijoe do
36
29
  system "git config --replace-all cijoe.runner 'rake test:rubies'"
@@ -38,10 +31,69 @@ namespace :setup do
38
31
 
39
32
  end
40
33
 
34
+ namespace :install do
35
+
36
+ desc "Install REE on Mac OS X Lion"
37
+ task :ree_on_lion do
38
+ system "rvm remove ree"
39
+ system "export CC=/usr/bin/gcc-4.2"
40
+ system "rvm install --force ree"
41
+ end
42
+
43
+ desc "Install JRuby and update Rubygems to latest version."
44
+ task :jruby_on_lion do
45
+ system "rvm remove jruby"
46
+ system "rvm install --force jruby"
47
+ system "rvm use jruby"
48
+ system "gem install rubygems-update"
49
+ system "update_rubygems"
50
+ system "gem update --system"
51
+ end
52
+
53
+ desc "Install common Rubies"
54
+ task :rubies do
55
+ system "rvm install 1.8.7,ree,1.9.2,jruby"
56
+ end
57
+
58
+ desc "Install latest Rubygems"
59
+ task :latest_rubygems do
60
+ system "rvm ruby gem update --system"
61
+ end
62
+
63
+ desc "Install bundler and rake"
64
+ task :bundler_and_rake do
65
+ system "rvm ruby gem install --no-ri --no-rdoc bundler rake"
66
+ end
67
+
68
+ desc "Run bundle in all Ruby versions."
69
+ task :gems do
70
+ system "rvm ruby bundle install --gemfile=test/fixtures/rails_app/Gemfile"
71
+ end
72
+
73
+ end
74
+
41
75
  namespace :test do
42
76
 
77
+ # Typus should be compatible with Ruby 1.8.7 and 1.9.2. Currently tests only
78
+ # pass when using 1.9.2 because on 1.8.7 we get an error because `fastercsv`
79
+ # is not loaded. This is because I've not added that library in the Gemfile.
80
+ desc "Test officially supported Ruby versions and database adapters"
81
+ task :supported do
82
+ system "rvm 1.9.2 rake test DB=sqlite3"
83
+ system "rvm 1.9.2 rake test DB=postgresql"
84
+ system "rvm 1.9.2 rake test DB=mysql"
85
+ end
86
+
87
+ # We want to test Typus with all supported databases:
88
+ #
89
+ # - Postgresql
90
+ # - MySQL
91
+ # - SQLite3
92
+ #
43
93
  task :rubies do
44
- system "rvm #{RUBIES} rake"
94
+ system "rvm ruby rake DB=sqlite3"
95
+ system "rvm ruby rake DB=postgresql"
96
+ system "rvm ruby rake DB=mysql"
45
97
  end
46
98
 
47
99
  end
@@ -18,6 +18,14 @@
18
18
  padding-left: 0.5em;
19
19
  }
20
20
 
21
+ #sidebar ul li a {
22
+ color: white;
23
+ }
24
+
25
+ #sidebar ul ul li a {
26
+ color: black;
27
+ }
28
+
21
29
  #sidebar a {
22
30
  text-decoration: none;
23
31
  }
@@ -2,7 +2,7 @@ module Admin::Resources::DataTypes::DateHelper
2
2
 
3
3
  def date_filter(filter)
4
4
  values = %w(today last_few_days last_7_days last_30_days)
5
- items = [[Typus::I18n.t("Show all dates"), ""]]
5
+ items = [[@resource.human_attribute_name(filter).capitalize, ""]]
6
6
  items += values.map { |v| [Typus::I18n.t(v.humanize), v] }
7
7
  end
8
8
 
@@ -11,7 +11,7 @@ module Admin::Resources::DataTypes::StringHelper
11
11
  alias_method :display_text, :display_string
12
12
 
13
13
  def string_filter(filter)
14
- values = set_context.send(filter.to_s).to_a
14
+ values = set_context.send(filter.to_s.pluralize).to_a
15
15
 
16
16
  items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
17
17
  array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
@@ -63,7 +63,7 @@ module Admin::Resources::FormHelper
63
63
  end
64
64
 
65
65
  def save_options_for_user_class
66
- return unless Typus.user_class == @resource && admin_user.is_not_root?
66
+ return unless !defined?(Typus.user_class) && Typus.user_class == @resource && admin_user.is_not_root?
67
67
  { "_continue" => "Save and continue editing" }
68
68
  end
69
69
 
@@ -9,6 +9,7 @@
9
9
  <small><%= list_actions %></small>
10
10
  </h2>
11
11
 
12
+ <%= display_flash_message %>
12
13
  <%= render 'new' %>
13
14
 
14
15
  <%= render :partial => 'form',
@@ -10,5 +10,5 @@
10
10
 
11
11
  <li id="<%= attribute_id %>">
12
12
  <%= form.label attribute, "#{label_text} <small>#{message}</small>".html_safe %>
13
- <%= form.select attribute, @resource.send(attribute), options, html_options %>
13
+ <%= form.select attribute, @resource.send(attribute.pluralize), options, html_options %>
14
14
  </li>
@@ -1,9 +1,13 @@
1
- <!-- Sidebar -->
1
+ <% content_for :main_grid do %>
2
+ <h2><%= resource.titleize %></h2>
2
3
 
3
- <%= sidebar -%>
4
+ <p>Find me in app/views/<%= resource.underscore %>/index.html.erb</p>
5
+ <% end %>
4
6
 
5
- <!-- Content -->
7
+ <div class="grid_2">
8
+ <%= sidebar %>
9
+ </div>
6
10
 
7
- <h2><%= resource.titleize %></h2>
8
-
9
- <p>Find me in app/views/<%= resource.underscore %>/index.html.erb</p>
11
+ <div class="grid_8">
12
+ <%= yield :main_grid %>
13
+ </div>
@@ -10,9 +10,11 @@ class ActiveRecord::Base
10
10
  # On a model:
11
11
  #
12
12
  # class Post < ActiveRecord::Base
13
- # STATUS = { t("Published") => "published",
14
- # t("Pending") => "pending",
15
- # t("Draft") => "draft" }
13
+ # def self.statuses
14
+ # { t("Published") => "published",
15
+ # t("Pending") => "pending",
16
+ # t("Draft") => "draft" }
17
+ # end
16
18
  # end
17
19
  #
18
20
  # >> Post.first.status
@@ -26,7 +28,7 @@ class ActiveRecord::Base
26
28
  #++
27
29
  def mapping(attribute)
28
30
  klass = self.class
29
- values = klass.send(attribute)
31
+ values = klass.send(attribute.to_s.pluralize)
30
32
 
31
33
  array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
32
34
 
@@ -34,7 +36,7 @@ class ActiveRecord::Base
34
36
  value ? value.first : send(attribute)
35
37
  end
36
38
 
37
- def to_label
39
+ def to_str
38
40
  if respond_to?(:name) && send(:name).present?
39
41
  send(:name)
40
42
  else
@@ -42,4 +44,6 @@ class ActiveRecord::Base
42
44
  end
43
45
  end
44
46
 
47
+ alias_method :to_label, :to_str
48
+
45
49
  end
data/lib/typus.rb CHANGED
@@ -22,6 +22,7 @@ module Typus
22
22
  module Controller
23
23
  autoload :Actions, "typus/controller/actions"
24
24
  autoload :ActsAsList, "typus/controller/acts_as_list"
25
+ autoload :Ancestry, "typus/controller/ancestry"
25
26
  autoload :Associations, "typus/controller/associations"
26
27
  autoload :Autocomplete, "typus/controller/autocomplete"
27
28
  autoload :Bulk, "typus/controller/bulk"
@@ -7,7 +7,9 @@ module Typus
7
7
  include Base
8
8
 
9
9
  def authenticate
10
- session[:typus_user_id] ? admin_user : redirect_to(new_admin_session_path)
10
+ unless session[:typus_user_id] && admin_user && admin_user.active?
11
+ deauthenticate
12
+ end
11
13
  end
12
14
 
13
15
  def deauthenticate
@@ -21,12 +23,6 @@ module Typus
21
23
  #++
22
24
  def admin_user
23
25
  @admin_user ||= Typus.user_class.find_by_id(session[:typus_user_id])
24
-
25
- if !@admin_user || !Typus::Configuration.roles.has_key?(@admin_user.role) || !@admin_user.status
26
- deauthenticate
27
- end
28
-
29
- @admin_user
30
26
  end
31
27
 
32
28
  #--
@@ -0,0 +1,30 @@
1
+ module Typus
2
+ module Controller
3
+ module Ancestry
4
+
5
+ def index
6
+ items = []
7
+
8
+ @resource.roots.each do |item|
9
+ items << item
10
+ if item.has_children?
11
+ item.children.each do |child|
12
+ items << child
13
+ if child.has_children?
14
+ child.children.each do |child|
15
+ items << child
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ @items = Kaminari.paginate_array(items).page(params[:page]).per(1000)
23
+
24
+ add_resource_action(default_action.titleize, {:action => default_action}, {})
25
+ add_resource_action("Trash", {:action => "destroy"}, {:confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete'})
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -1,9 +1,4 @@
1
- if RUBY_VERSION >= '1.9'
2
- require 'csv'
3
- else
4
- require 'fastercsv'
5
- CSV = FasterCSV
6
- end
1
+ require 'csv'
7
2
 
8
3
  module Typus
9
4
  module Controller
@@ -22,91 +22,86 @@ module Typus
22
22
  # Form and list fields
23
23
  def typus_fields_for(filter)
24
24
  ActiveSupport::OrderedHash.new.tap do |fields_with_type|
25
- data = read_model_config['fields']
26
-
27
- ##
28
- # Let's say for example we want to get the fields for actions
29
- # related with editing stuff.
30
- #
31
-
32
- fields = case filter.to_sym
33
- when :list, :form
34
- # TODO: This statement is for backwards compatibility
35
- # with the current tests, so can be removed in
36
- # the near future.
37
- data[filter.to_s] || data['default'] || ""
38
- when :index
39
- data['index'] || data['list'] || data['default'] || ""
40
- when :new, :create
41
- data['new'] || data['form'] || data['default'] || ""
42
- when :edit, :update, :toggle
43
- data['edit'] || data['form'] || data['default'] || ""
44
- else
45
- data[filter.to_s] || data['default'] || ""
46
- end
47
-
48
- virtual_fields = instance_methods.map { |i| i.to_s } - model_fields.keys.map { |i| i.to_s }
49
-
50
- fields.extract_settings.map { |f| f.to_sym }.each do |field|
51
- if reflect_on_association(field)
52
- fields_with_type[field.to_s] = reflect_on_association(field).macro
53
- next
25
+ get_typus_fields_for(filter).each do |field|
26
+ [:virtual, :custom, :association, :selector, :dragonfly, :paperclip].each do |attribute|
27
+ if (value = send("#{attribute}_attribute?", field))
28
+ fields_with_type[field.to_s] = value
29
+ end
54
30
  end
31
+ fields_with_type[field.to_s] ||= model_fields[field]
32
+ end
33
+ end
34
+ end
55
35
 
56
- if typus_field_options_for(:selectors).include?(field)
57
- fields_with_type[field.to_s] = :selector
58
- next
59
- end
36
+ def get_typus_fields_for(filter)
37
+ data = read_model_config['fields']
38
+ fields = case filter.to_sym
39
+ when :index then data['index'] || data['list']
40
+ when :new, :create then data['new'] || data['form']
41
+ when :edit, :update, :toggle then data['edit'] || data['form']
42
+ else
43
+ data[filter.to_s]
44
+ end
45
+
46
+ fields ||= data['default'] || typus_default_fields_for(filter)
47
+ fields = fields.extract_settings if fields.is_a?(String)
48
+ fields.map { |f| f.to_sym }
49
+ end
60
50
 
61
- dragonfly = respond_to?(:dragonfly_attachment_classes) && dragonfly_attachment_classes.map { |i| i.attribute }.include?(field)
62
- paperclip = respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
51
+ def typus_default_fields_for(filter)
52
+ filter.to_sym.eql?(:index) ? ['id'] : model_fields.keys
53
+ end
63
54
 
64
- if respond_to?(:dragonfly_attachment_classes) && dragonfly_attachment_classes.map { |i| i.attribute }.include?(field)
65
- fields_with_type[field.to_s] = :dragonfly
66
- next
67
- end
55
+ def virtual_fields
56
+ instance_methods.map { |i| i.to_s } - model_fields.keys.map { |i| i.to_s }
57
+ end
68
58
 
69
- if respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
70
- fields_with_type[field.to_s] = :paperclip
71
- next
72
- end
59
+ def virtual_attribute?(field)
60
+ :virtual if virtual_fields.include?(field.to_s)
61
+ end
73
62
 
74
- # TODO: This is not tested!
75
- if virtual_fields.include?(field.to_s)
76
- fields_with_type[field.to_s] = :virtual
77
- end
63
+ def dragonfly_attribute?(field)
64
+ if respond_to?(:dragonfly_attachment_classes) && dragonfly_attachment_classes.map { |i| i.attribute }.include?(field)
65
+ :dragonfly
66
+ end
67
+ end
68
+
69
+ def paperclip_attribute?(field)
70
+ if respond_to?(:attachment_definitions) && attachment_definitions.try(:has_key?, field)
71
+ :paperclip
72
+ end
73
+ end
78
74
 
79
- fields_with_type[field.to_s] = case field.to_s
80
- when 'parent', 'parent_id' then :tree
81
- when /password/ then :password
82
- when 'position' then :position
83
- when /\./ then :transversal
84
- else
85
- if fields_with_type[field.to_s]
86
- fields_with_type[field.to_s]
87
- else
88
- model_fields[field]
89
- end
90
- end
75
+ def selector_attribute?(field)
76
+ :selector if typus_field_options_for(:selectors).include?(field)
77
+ end
91
78
 
92
- end
79
+ def association_attribute?(field)
80
+ reflect_on_association(field).macro if reflect_on_association(field)
81
+ end
82
+
83
+ def custom_attribute?(field)
84
+ case field.to_s
85
+ when 'parent', 'parent_id' then :tree
86
+ when /password/ then :password
87
+ when 'position' then :position
88
+ when /\./ then :transversal
93
89
  end
94
90
  end
95
91
 
96
92
  def typus_filters
97
93
  ActiveSupport::OrderedHash.new.tap do |fields_with_type|
98
- if data = read_model_config['filters']
99
- data.extract_settings.map { |i| i.to_sym }.each do |field|
100
- attribute_type = model_fields[field.to_sym]
101
- if reflect_on_association(field.to_sym)
102
- attribute_type = reflect_on_association(field.to_sym).macro
103
- end
104
- fields_with_type[field.to_s] = attribute_type
105
- end
94
+ get_typus_filters.each do |field|
95
+ fields_with_type[field.to_s] = association_attribute?(field) || model_fields[field.to_sym]
106
96
  end
107
97
  end
108
98
  end
109
99
 
100
+ def get_typus_filters
101
+ data = read_model_config['filters'] || ""
102
+ data.extract_settings.map { |i| i.to_sym }
103
+ end
104
+
110
105
  end
111
106
  end
112
107
  end
@@ -13,11 +13,11 @@ module Typus
13
13
  user.save ? user : false
14
14
  end
15
15
 
16
- def role
16
+ def roles
17
17
  Typus::Configuration.roles.keys.sort
18
18
  end
19
19
 
20
- def locale
20
+ def locales
21
21
  Typus::I18n.available_locales
22
22
  end
23
23
 
@@ -47,6 +47,10 @@ module Typus
47
47
  !is_root?
48
48
  end
49
49
 
50
+ def active?
51
+ status && Typus::Configuration.roles.has_key?(role)
52
+ end
53
+
50
54
  def locale
51
55
  (preferences && preferences[:locale]) ? preferences[:locale] : ::I18n.default_locale
52
56
  end
@@ -5,6 +5,9 @@ module Typus
5
5
 
6
6
  include Typus::Orm::Base
7
7
 
8
+ def table_name
9
+ self.collection_name
10
+ end
8
11
  end
9
12
  end
10
13
  end
data/lib/typus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Typus
2
- VERSION = "3.1.0.rc17"
2
+ VERSION = "3.1.0.rc18"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.rc17
4
+ version: 3.1.0.rc18
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-17 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2011-08-12 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: dragonfly
17
- requirement: &2160603900 !ruby/object:Gem::Requirement
16
+ requirement: &70096177538180 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0.9'
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *2160603900
24
+ version_requirements: *70096177538180
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: jquery-rails
28
- requirement: &2160603360 !ruby/object:Gem::Requirement
27
+ requirement: &70096175063500 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2160603360
35
+ version_requirements: *70096175063500
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: paperclip
39
- requirement: &2160602800 !ruby/object:Gem::Requirement
38
+ requirement: &70096175063040 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2160602800
46
+ version_requirements: *70096175063040
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: rack-cache
50
- requirement: &2160602300 !ruby/object:Gem::Requirement
49
+ requirement: &70096175062620 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2160602300
57
+ version_requirements: *70096175062620
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: rails-trash
61
- requirement: &2160601740 !ruby/object:Gem::Requirement
60
+ requirement: &70096175062120 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ~>
@@ -66,10 +65,10 @@ dependencies:
66
65
  version: 1.1.1
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *2160601740
68
+ version_requirements: *70096175062120
70
69
  - !ruby/object:Gem::Dependency
71
70
  name: jquery-rails
72
- requirement: &2160601260 !ruby/object:Gem::Requirement
71
+ requirement: &70096175061700 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ! '>='
@@ -77,10 +76,10 @@ dependencies:
77
76
  version: '0'
78
77
  type: :runtime
79
78
  prerelease: false
80
- version_requirements: *2160601260
79
+ version_requirements: *70096175061700
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: kaminari
83
- requirement: &2160600680 !ruby/object:Gem::Requirement
82
+ requirement: &70096175061240 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
86
85
  - - ! '>='
@@ -88,10 +87,10 @@ dependencies:
88
87
  version: '0'
89
88
  type: :runtime
90
89
  prerelease: false
91
- version_requirements: *2160600680
90
+ version_requirements: *70096175061240
92
91
  - !ruby/object:Gem::Dependency
93
92
  name: sass-rails
94
- requirement: &2160600000 !ruby/object:Gem::Requirement
93
+ requirement: &70096175060740 !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ~>
@@ -99,10 +98,10 @@ dependencies:
99
98
  version: 3.1.0.rc.2
100
99
  type: :runtime
101
100
  prerelease: false
102
- version_requirements: *2160600000
101
+ version_requirements: *70096175060740
103
102
  - !ruby/object:Gem::Dependency
104
103
  name: rails
105
- requirement: &2160599380 !ruby/object:Gem::Requirement
104
+ requirement: &70096175060240 !ruby/object:Gem::Requirement
106
105
  none: false
107
106
  requirements:
108
107
  - - ~>
@@ -110,7 +109,7 @@ dependencies:
110
109
  version: 3.1.0.rc4
111
110
  type: :runtime
112
111
  prerelease: false
113
- version_requirements: *2160599380
112
+ version_requirements: *70096175060240
114
113
  description: Ruby on Rails Admin Panel (Engine) to allow trusted users edit structured
115
114
  content.
116
115
  email:
@@ -270,6 +269,7 @@ files:
270
269
  - lib/typus/configuration.rb
271
270
  - lib/typus/controller/actions.rb
272
271
  - lib/typus/controller/acts_as_list.rb
272
+ - lib/typus/controller/ancestry.rb
273
273
  - lib/typus/controller/associations.rb
274
274
  - lib/typus/controller/autocomplete.rb
275
275
  - lib/typus/controller/bulk.rb
@@ -383,7 +383,6 @@ files:
383
383
  - config/locales/typus.ru.yml
384
384
  - config/locales/typus.zh-CN.models.yml
385
385
  - config/locales/typus.zh-CN.yml
386
- has_rdoc: true
387
386
  homepage: http://core.typuscms.com/
388
387
  licenses: []
389
388
  post_install_message:
@@ -404,7 +403,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
403
  version: 1.3.1
405
404
  requirements: []
406
405
  rubyforge_project: typus
407
- rubygems_version: 1.6.2
406
+ rubygems_version: 1.8.7
408
407
  signing_key:
409
408
  specification_version: 3
410
409
  summary: Effortless backend interface for Ruby on Rails applications. (Admin scaffold