kitsune 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rake'
2
2
 
3
3
  gem_spec = Gem::Specification.new do |gem_spec|
4
4
  gem_spec.name = "kitsune"
5
- gem_spec.version = "0.0.2"
5
+ gem_spec.version = "0.0.3"
6
6
  gem_spec.summary = "Integrated Rails Content Management System."
7
7
  gem_spec.email = "matt@toastyapps.com"
8
8
  gem_spec.homepage = "http://github.com/toastyapps/kitsune"
@@ -0,0 +1,20 @@
1
+ class Admin::Kitsune::ApplicationController < ActionController::Base
2
+ before_filter :load_models
3
+
4
+ private
5
+ def load_models
6
+ models = Kitsune.models_with_admin.map{ |m| Kitsune::Inspector.new(m) }
7
+ # category_map = {}
8
+ # @models =[]
9
+ # models.each do |m|
10
+ # if m.category
11
+ # category_map[m.category] = [] unless category[m.category]
12
+ # category_map[m.category] << m
13
+ # else
14
+ # @models << m
15
+ # end
16
+ # end
17
+ # @models += category_map.to_a.map{|c| Hash[*c]}
18
+ @models = models
19
+ end
20
+ end
@@ -1,10 +1,7 @@
1
- class Admin::Kitsune::ModelsController < ApplicationController
1
+ class Admin::Kitsune::ModelsController < Admin::Kitsune::ApplicationController
2
2
  layout 'admin/kitsune'
3
3
 
4
4
  before_filter :load_model
5
- def index
6
- @models = Kitsune.models_with_admin
7
- end
8
5
 
9
6
  private
10
7
  def load_model
@@ -1,4 +1,4 @@
1
- class Admin::Kitsune::PagesController < ApplicationController
1
+ class Admin::Kitsune::PagesController < Admin::Kitsune::ApplicationController
2
2
  layout 'admin/kitsune'
3
3
 
4
4
  before_filter :load_page
@@ -1,4 +1,4 @@
1
- class Admin::Kitsune::RecordsController < ApplicationController
1
+ class Admin::Kitsune::RecordsController < Admin::Kitsune::ApplicationController
2
2
  layout 'admin/kitsune'
3
3
 
4
4
  before_filter :load_model
@@ -19,7 +19,12 @@ class Admin::Kitsune::RecordsController < ApplicationController
19
19
  end
20
20
 
21
21
  def create
22
- @record = @model.new_record(params[params[:model_id].underscore])
22
+ if @model.is_sti? && params[params[:model_id].underscore][@model.sti_column].present?
23
+ sti_model = Kitsune::Inspector.new(params[params[:model_id].underscore].delete(@model.sti_column).constantize)
24
+ @record = sti_model.new_record(params[params[:model_id].underscore])
25
+ else
26
+ @record = @model.new_record(params[params[:model_id].underscore])
27
+ end
23
28
  if @record.save
24
29
  flash[:notice] = "Record Saved"
25
30
  redirect_to admin_kitsune_model_records_path(params[:model_id])
@@ -1,3 +1,4 @@
1
- <% @models.each do |model| %>
2
- <%= link_to model, admin_kitsune_model_records_path(model) %>
3
- <% end %>
1
+ <div class='kitsune_right'>
2
+ Use the left menu to manage your site. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
3
+ </div>
4
+
@@ -1,7 +1,7 @@
1
- <div id='menu'>
2
- <%= link_to 'Back', admin_kitsune_model_records_path(params[:model_id]) %>
1
+ <div id='kitsune_record_header'>
2
+ <h2 class='legend'>Edit <%= params[:model_id] %></h2>
3
+ <div id='menu'>
4
+ <%= link_to 'Back', admin_kitsune_model_records_path(params[:model_id]) %>
5
+ </div>
3
6
  </div>
4
- <div id='body'>
5
- <h2 class='legend'>Edit <%= params[:model_id] %></h3>
6
- <%= render 'form' %>
7
- </div>
7
+ <%= render 'form' %>
@@ -1,9 +1,9 @@
1
- <div id='menu'>
2
- <%= link_to 'Back', admin_kitsune_models_path %>
3
- |
4
- <%= link_to "New #{params[:id]}", new_admin_kitsune_model_record_path(params[:model_id]) %>
1
+ <div id='kitsune_record_header'>
2
+ <h2><%= @model.admin_name %></h2>
3
+ <div id='menu'>
4
+ <%= link_to "New #{params[:id]}", new_admin_kitsune_model_record_path(params[:model_id]) %>
5
+ </div>
5
6
  </div>
6
- <div id='body'>
7
7
  <% @model.tabs.each do |key, value|%>
8
8
  <%= link_to key, value %>
9
9
  <% end %>
@@ -32,5 +32,4 @@
32
32
  </tbody>
33
33
  </table>
34
34
 
35
- <%= will_paginate @records %>
36
- </div>
35
+ <%= will_paginate @records %>
@@ -1,7 +1,8 @@
1
- <div id='menu'>
2
- <%= link_to 'Back', admin_kitsune_model_records_path(params[:model_id]) %>
1
+ <div id='kitsune_record_header'>
2
+ <h2 class='legend'>New <%= params[:model_id] %></h2>
3
+ <div id='menu'>
4
+ <%= link_to 'Back', admin_kitsune_model_records_path(params[:model_id]) %>
5
+ </div>
3
6
  </div>
4
- <div id='body'>
5
- <h2 class='legend'>New <%= params[:model_id] %></h3>
6
- <%= render 'form' %>
7
- </div>
7
+
8
+ <%= render 'form' %>
@@ -8,8 +8,18 @@
8
8
  <div id='content'>
9
9
  <div id='header'>
10
10
  <h1><a href='/admin/models'>Kitsune</a></h1>
11
+ <a href='/'>View Site</a>
12
+ </div>
13
+ <div class='kitsune_container'>
14
+ <div class='kitsune_left'>
15
+ <% @models.each do |model| %>
16
+ <div class='kitsune_model_link'><%= link_to model.admin_name, admin_kitsune_model_records_path(model.object_class) %></div>
17
+ <% end %>
18
+ </div>
19
+ <div class='kitsune_right'>
20
+ <%= yield %>
21
+ </div>
11
22
  </div>
12
- <%= yield %>
13
23
  </div>
14
24
  </body>
15
25
  </html>
@@ -0,0 +1 @@
1
+ script/generate kitsune
@@ -16,11 +16,11 @@ class KitsuneGenerator < Rails::Generator::Base
16
16
  m.directory "public/stylesheets/kitsune/"
17
17
  m.file "stylesheets/global.css", "public/stylesheets/kitsune/global.css"
18
18
  m.directory "public/images/kitsune/"
19
- %w[bg.jpg form-bg.gif grey-btn.png nicEditorIcons.gif].each do |image|
19
+ %w[bg.jpg form-bg.gif header-link.png grey-btn.png nicEditorIcons.gif].each do |image|
20
20
  m.file "images/#{image}", "public/images/kitsune/#{image}"
21
21
  end
22
22
 
23
-
23
+ m.readme "README"
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,18 @@
1
+ *******************************************************************************
2
+
3
+ Only two steps remain!
4
+
5
+ 1. Add this to environment.rb if it's not there already
6
+
7
+ config.gem 'will_paginate', :source => 'http://gemcutter.org'
8
+
9
+ and run
10
+
11
+ rake gems:install
12
+
13
+ 2. Please make sure to delete the two default routes:
14
+
15
+ map.connect ':controller/:action/:id'
16
+ map.connect ':controller/:action/:id.:format'
17
+
18
+ *******************************************************************************
@@ -88,15 +88,77 @@ body {
88
88
 
89
89
  #header {
90
90
  width: 100%;
91
- height: 25px;
92
- padding: 8px 0 6px 0;
91
+ height: 38px;
93
92
 
94
93
  }
95
94
 
96
- h1 a {
95
+ #header h1 {
96
+ float: left;
97
+ padding-top: 8px;
98
+ margin-left: 15px;
99
+ }
100
+
101
+ #header > a {
102
+ height: 38px;
103
+ background: url(/images/kitsune/header-link.png) top left no-repeat;
104
+ width: 90px;
105
+ float: right;
106
+ margin-right: 15px;
107
+ color: #CCC;
108
+ font-size: 0.8em;
109
+ line-height: 38px;
110
+ text-align: center;
111
+ text-decoration:none;
112
+ }
113
+
114
+ #header > a:hover {
115
+ color: #FFF;
116
+ }
117
+
118
+ #header h1 a {
97
119
  text-decoration: none;
98
120
  color: #fff;
99
- margin-left: 10px;
121
+ }
122
+
123
+ .kitsune_container {
124
+ width:100%;
125
+ float: right;
126
+ margin-left: -250px;
127
+ }
128
+
129
+ .kitsune_left {
130
+ margin-top: 15px;
131
+ width: 250px;
132
+ padding: 15px;
133
+ float: left;
134
+ background: #FFF;
135
+ border: 1px solid #CCC;
136
+ margin-left: 15px;
137
+ }
138
+
139
+
140
+ .kitsune_right {
141
+ margin-left: 310px;
142
+ margin-right: 15px;
143
+ margin-top: 15px;
144
+ padding: 15px;
145
+ background: #FFF;
146
+ border: 1px solid #CCC;
147
+ }
148
+
149
+ #kitsune_record_header {
150
+ float:left;
151
+ width: 100%;
152
+ margin-bottom: 15px;
153
+ }
154
+
155
+ #kitsune_record_header h2 {
156
+ float:left;
157
+ width: 45%;
158
+ }
159
+
160
+ #kitsune_record_header #menu {
161
+ float: right;
100
162
  }
101
163
 
102
164
 
@@ -8,7 +8,7 @@ module Kitsune
8
8
  autoload :Page, 'kitsune/page'
9
9
  class << self
10
10
  def version
11
- '0.0.1'
11
+ '0.0.2'
12
12
  end
13
13
 
14
14
  def model_paths # abstract this to something else
@@ -16,7 +16,7 @@ module Kitsune
16
16
  end
17
17
 
18
18
  def models_with_admin
19
- models.select{|m| m.respond_to?(:kitsune_admin)} # quacks like a duck
19
+ models.select{|m| m.respond_to?(:kitsune_admin) && !m.kitsune_admin[:no_admin]} # quacks like a duck
20
20
  end
21
21
 
22
22
  def models
@@ -11,14 +11,15 @@ module Kitsune
11
11
  :display => {},
12
12
  :edit => {},
13
13
  :fields => {},
14
- :tabs => {}
14
+ :tabs => {},
15
+ :is_sti => false
15
16
  }
16
17
  end
17
18
  end
18
19
 
19
20
  def admin &block
20
- setup_admin
21
- Kitsune::Builder.generate(self, &block)
21
+ setup_admin unless self.respond_to?(:kitsune_admin)
22
+ Kitsune::Builder.generate(self, &block) unless self.kitsune_admin[:no_admin]
22
23
  end
23
24
 
24
25
  def no_admin
@@ -8,6 +8,14 @@ module Kitsune
8
8
  self.instance_eval &block
9
9
  end
10
10
 
11
+ def category category
12
+ @resource.kitsune_admin[:category] = category
13
+ end
14
+
15
+ def name name
16
+ @resource.kitsune_admin[:name] = name
17
+ end
18
+
11
19
  def no_admin
12
20
  @resource.kitsune_admin[:no_admin] = true
13
21
  end
@@ -36,7 +44,7 @@ module Kitsune
36
44
  end
37
45
 
38
46
  def file(field)
39
- add_definition(:file_field, field)
47
+ add :file_field, field
40
48
  multipart
41
49
  end
42
50
 
@@ -45,39 +53,49 @@ module Kitsune
45
53
  end
46
54
 
47
55
  def select(field, options)
48
- add_definition(:select, field, {:options => options})
56
+ add :select, field, {:options => options}
57
+ end
58
+
59
+ def sti(field, options = {})
60
+ add :sti, field, {:options => options}
61
+ is_sti field
62
+ end
63
+
64
+ def is_sti(field)
65
+ @resource.kitsune_admin[:is_sti] = true
66
+ @resource.kitsune_admin[:sti_column] = field
49
67
  end
50
68
 
51
69
  def display_and_edit(*args)
52
- display(*args)
53
- edit(*args)
70
+ display *args
71
+ edit *args
54
72
  end
55
73
 
56
74
  def display(*fields)
57
- set_options_for_fields(:display, fields)
75
+ set :display, fields
58
76
  end
59
77
 
60
78
  def edit(*fields)
61
- set_options_for_fields(:edit, fields)
79
+ set :edit, fields
62
80
  end
63
81
 
64
82
  def no_edit(*fields)
65
- set_options_for_fields(:no_edit, fields)
83
+ set :no_edit, fields
66
84
  end
67
85
 
68
86
  def method_missing(method, *args, &block)
69
87
  if TYPES.include?(method)
70
- add_definition(method, *args)
88
+ add method, *args
71
89
  end
72
90
  end
73
91
 
74
92
  private
75
- def add_definition(type, field, options = {})
93
+ def add(type, field, options = {})
76
94
  @resource.kitsune_admin[:fields] ||= {}
77
95
  @resource.kitsune_admin[:fields][field] = options.merge(:type => type)
78
96
  end
79
97
 
80
- def set_options_for_fields(type, fields)
98
+ def set(type, fields)
81
99
  @resource.kitsune_admin[type] = {} unless @resource.kitsune_admin[type]
82
100
  @resource.kitsune_admin[type][:fields] ||= []
83
101
  fields.each do |field|
@@ -9,12 +9,28 @@ module Kitsune
9
9
  @collection_label_methods = %w[to_label display_name full_name name title username login value to_s]
10
10
  end
11
11
 
12
+ def admin_name
13
+ kitsune_admin[:name] || @object.to_s.pluralize
14
+ end
15
+
16
+ def category
17
+ kitsune_admin[:category] || nil
18
+ end
19
+
20
+ def is_sti?
21
+ kitsune_admin[:is_sti]
22
+ end
23
+
24
+ def sti_column
25
+ kitsune_admin[:sti_column]
26
+ end
27
+
12
28
  def tabs
13
29
  kitsune_admin[:tabs]
14
30
  end
15
31
 
16
32
  def object_class
17
- @object.class
33
+ @object.to_s
18
34
  end
19
35
 
20
36
  def new_record(*args)
@@ -67,7 +83,16 @@ module Kitsune
67
83
 
68
84
  def form_type(column)
69
85
  if kitsune_admin[:fields][column.name.to_sym] && kitsune_admin[:fields][column.name.to_sym][:type]
70
- kitsune_admin[:fields][column.name.to_sym][:type]
86
+ case kitsune_admin[:fields][column.name.to_sym][:type]
87
+ when :sti
88
+ if kitsune_admin[:fields][column.name.to_sym][:options] && kitsune_admin[:fields][column.name.to_sym][:options][:classes]
89
+ :select
90
+ else
91
+ :text_field
92
+ end
93
+ else
94
+ kitsune_admin[:fields][column.name.to_sym][:type]
95
+ end
71
96
  elsif column.name =~ /_id$/
72
97
  :select
73
98
  else
@@ -76,6 +101,7 @@ module Kitsune
76
101
  when :datetime then :datetime_select
77
102
  when :date then :date_select
78
103
  when :time then :time_select
104
+ when :boolean then :check_box
79
105
  else :text_field
80
106
  end
81
107
  end
@@ -127,6 +153,8 @@ module Kitsune
127
153
  collection = find_association_class(column).all
128
154
  name = detect_label(collection)
129
155
  [collection.map { |r| [ r.send(name), r.send(id) ] }, {:include_blank => true}]
156
+ elsif kitsune_admin[:fields][column.name.to_sym] && kitsune_admin[:fields][column.name.to_sym][:type] == :sti && kitsune_admin[:fields][column.name.to_sym][:options] && kitsune_admin[:fields][column.name.to_sym][:options][:classes]
157
+ [kitsune_admin[:fields][column.name.to_sym][:options][:classes].map {|c| [c.to_s, c.to_s]}, {:include_blank => true}]
130
158
  else
131
159
  options = {}
132
160
  options[:size] = '80x10' if [:text_area, :wysiwyg].include?(form_type(column))
@@ -1,3 +1,2 @@
1
1
  require 'kitsune'
2
-
3
2
  ActiveRecord::Base.extend(Kitsune::ActiveRecord)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitsune
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau <matt@toastyapps.com>
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-23 00:00:00 -04:00
12
+ date: 2009-11-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - Rakefile
35
35
  - README.textile
36
+ - app/controllers/admin/kitsune/application_controller.rb
36
37
  - app/controllers/admin/kitsune/models_controller.rb
37
38
  - app/controllers/admin/kitsune/pages_controller.rb
38
39
  - app/controllers/admin/kitsune/records_controller.rb
@@ -56,11 +57,14 @@ files:
56
57
  - generators/kitsune/templates/images/bg.jpg
57
58
  - generators/kitsune/templates/images/form-bg.gif
58
59
  - generators/kitsune/templates/images/grey-btn.png
60
+ - generators/kitsune/templates/images/header-link.png
59
61
  - generators/kitsune/templates/images/nicEditorIcons.gif
60
62
  - generators/kitsune/templates/javascripts/nicEdit.js
61
63
  - generators/kitsune/templates/migrations/create_pages.rb
62
64
  - generators/kitsune/templates/page.rb
65
+ - generators/kitsune/templates/README
63
66
  - generators/kitsune/templates/stylesheets/global.css
67
+ - generators/kitsune/USAGE
64
68
  - lib/kitsune/active_record.rb
65
69
  - lib/kitsune/builder.rb
66
70
  - lib/kitsune/extensions/routes.rb