kitsune 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -1,6 +1,7 @@
1
1
  class KitsuneController < ApplicationController
2
2
  def show
3
- @page = ::Page.find_by_url([params[:url]].flatten.join('/'))
3
+ @page = ::Page.find_by_url('/'+[params[:url]].flatten.join('/'))
4
+ raise ::ActionController::RoutingError, "No route matches #{request.path.inspect}" unless @page.present?
4
5
  @title = @page.title
5
6
  end
6
7
  end
@@ -15,7 +15,7 @@
15
15
  = link_to 'Current Version &rarr;', :version => nil
16
16
  - @model.columns(:edit).each do |column|
17
17
  .field
18
- - unless params[column.name]
18
+ - unless params[column.name] && !@model.always?(column)
19
19
  = form.label column.name
20
20
  = form.send(@model.form_type(column), column.name, *@model.options_for(column))
21
21
  = additional_content_for(@model, @record, column)
@@ -3,22 +3,24 @@
3
3
  %tr
4
4
  - model.columns(:display).each do |column|
5
5
  %th= sort_link_to(model, column)
6
- %th Actions
6
+ - unless model.disabled?(:edit) && model.disabled?(:delete)
7
+ %th Actions
7
8
  %tbody
8
9
  - records.each do |record|
9
10
  %tr{:class=>cycle('odd', 'even')}
10
11
  - model.columns(:display).each do |column|
11
- %td= sanitize(model.display_for(record, column.name).to_s)
12
- %td
13
- - unless model.disabled?(:edit)
14
- - if parent
15
- = link_to 'Edit', :controller => 'admin/kitsune/records', :action => :edit, :model_id => model.object_class, :id => record.id, (parent.class.to_s.underscore+'_id').to_sym => parent.id
16
- - else
17
- = link_to 'Edit', :controller => 'admin/kitsune/records', :action => :edit, :model_id => model.object_class, :id => record.id
18
- - unless model.disabled?(:edit) || model.disabled?(:delete)
19
- \-
20
- - unless model.disabled?(:delete)
21
- - if parent
22
- = link_to('Delete', url_for(:controller => 'admin/kitsune/records', :model_id => model.object_class, :id => record.id, :action => :destroy, :redirect => (parent.class.to_s.underscore+'_id'), :redirect_id => parent.id), :method => :delete, :confirm => "Are you sure?")
23
- - else
24
- = link_to('Delete', url_for(:controller => 'admin/kitsune/records', :model_id => model.object_class, :id => record.id, :action => :destroy), :method => :delete, :confirm => "Are you sure?")
12
+ %td= model.column_linked?(column) ? link_to(sanitize(model.display_for(record, column.name).to_s), url_for(:controller => 'admin/kitsune/records', :action => :show, :model_id => model.object_class, :id => record.id)): sanitize(model.display_for(record, column.name).to_s)
13
+ - unless model.disabled?(:edit) && model.disabled?(:delete)
14
+ %td
15
+ - unless model.disabled?(:edit)
16
+ - if parent
17
+ = link_to 'Edit', :controller => 'admin/kitsune/records', :action => :edit, :model_id => model.object_class, :id => record.id, (parent.class.to_s.underscore+'_id').to_sym => parent.id
18
+ - else
19
+ = link_to 'Edit', :controller => 'admin/kitsune/records', :action => :edit, :model_id => model.object_class, :id => record.id
20
+ - unless model.disabled?(:edit) || model.disabled?(:delete)
21
+ \-
22
+ - unless model.disabled?(:delete)
23
+ - if parent
24
+ = link_to('Delete', url_for(:controller => 'admin/kitsune/records', :model_id => model.object_class, :id => record.id, :action => :destroy, :redirect => (parent.class.to_s.underscore+'_id'), :redirect_id => parent.id), :method => :delete, :confirm => "Are you sure?")
25
+ - else
26
+ = link_to('Delete', url_for(:controller => 'admin/kitsune/records', :model_id => model.object_class, :id => record.id, :action => :destroy), :method => :delete, :confirm => "Are you sure?")
@@ -4,9 +4,3 @@
4
4
  = link_to 'Back', :controller => 'admin/kitsune/records', :model_id => params[:model_id]
5
5
 
6
6
  = render 'form'
7
-
8
- - @model.columns(:reflections).each do |column|
9
- .reflection
10
- %h3= column.name.to_s.titleize
11
- = link_to 'New', :controller => 'admin/kitsune/records', :action => :new, :model_id => column.name.to_s.classify, (@record.class.to_s.underscore+'_id').to_sym => @record.id
12
- = render :partial => 'list', :locals => { :model => Kitsune::Inspector.new(column.name.to_s.classify.constantize), :records => @record.send(column.name), :parent => @record }
@@ -0,0 +1,11 @@
1
+ #kitsune_record_header
2
+ %h2.legend Show #{params[:model_id]}
3
+ %dl
4
+ - @model.columns(:show).each do |column|
5
+ %dt= column.name.capitalize
6
+ %dd= @record.send(column.name)
7
+ - @model.columns(:reflections).each do |column|
8
+ .reflection
9
+ %h3= column.name.to_s.titleize
10
+ = link_to 'New', :controller => 'admin/kitsune/records', :action => :new, :model_id => column.name.to_s.classify, (@record.class.to_s.underscore+'_id').to_sym => @record.id
11
+ = render :partial => 'list', :locals => { :model => Kitsune::Inspector.new(column.name.to_s.classify.constantize), :records => @record.send(column.name), :parent => @record }
data/kitsune.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kitsune}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["toastyapps", "<matt@toastyapps.com>"]
12
- s.date = %q{2010-01-11}
12
+ s.date = %q{2010-01-15}
13
13
  s.description = %q{Integrated Rails Content Management System.}
14
14
  s.email = %q{matt@toastyapps.com}
15
15
  s.extra_rdoc_files = [
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
44
44
  "app/views/admin/kitsune/records/edit.html.haml",
45
45
  "app/views/admin/kitsune/records/index.html.haml",
46
46
  "app/views/admin/kitsune/records/new.html.haml",
47
+ "app/views/admin/kitsune/records/show.html.haml",
47
48
  "app/views/admin/kitsune/sessions/new.html.haml",
48
49
  "app/views/admin/kitsune/shared/_flashes.html.haml",
49
50
  "app/views/kitsune/show.html.erb",
@@ -10,6 +10,7 @@ module Kitsune
10
10
  :multipart => false,
11
11
  :display => {},
12
12
  :edit => {},
13
+ :show => {},
13
14
  :reflections => {},
14
15
  :fields => {},
15
16
  :tabs => {},
@@ -25,6 +25,7 @@ module Kitsune
25
25
  end
26
26
 
27
27
  def order_by(order)
28
+ order = {order => :asc} unless order.is_a?(Hash)
28
29
  @resource.kitsune_admin[:order_by] = order
29
30
  end
30
31
 
@@ -67,6 +68,20 @@ module Kitsune
67
68
  end
68
69
  end
69
70
 
71
+ def always(*fields)
72
+ @resource.kitsune_admin[:always] ||= []
73
+ fields.each do |field|
74
+ @resource.kitsune_admin[:always] << field.to_sym
75
+ end
76
+ end
77
+
78
+ def linked(*fields) # link to resource
79
+ @resource.kitsune_admin[:linked] ||= []
80
+ fields.each do |field|
81
+ @resource.kitsune_admin[:linked] << field.to_sym
82
+ end
83
+ end
84
+
70
85
  def file(field)
71
86
  add :file_field, field
72
87
  multipart
@@ -121,6 +136,19 @@ module Kitsune
121
136
  end
122
137
  end
123
138
 
139
+ def show(*fields)
140
+ fields.each do |field|
141
+ if field.is_a?(Hash)
142
+ field.each do |key, value|
143
+ set :show, key
144
+ set_attributes(key, value)
145
+ end
146
+ else
147
+ set :show, field
148
+ end
149
+ end
150
+ end
151
+
124
152
  def set_attributes(field, attributes)
125
153
  [attributes].flatten.each do |attribute|
126
154
  send(attribute.to_sym, field)
@@ -67,7 +67,7 @@ module Kitsune
67
67
  else
68
68
  kolumns = send("columns_for_#{type}") if respond_to?("columns_for_#{type}")
69
69
  end
70
- include_pk ? kolumns : kolumns.reject{|c| c.primary }
70
+ include_pk ? kolumns : (kolumns || []).reject{|c| c.primary }
71
71
  end
72
72
 
73
73
  def columns_for_edit
@@ -102,6 +102,21 @@ module Kitsune
102
102
  end
103
103
  end
104
104
 
105
+ def columns_for_show
106
+ columns = @object.columns.dup
107
+ if kitsune_admin[:show] && kitsune_admin[:show][:fields]
108
+ columns = columns.select{|c| kitsune_admin[:show][:fields].include?(c.name.to_sym)}
109
+ column_names = columns.map{|c| c.name.to_sym}
110
+ fields_to_add = kitsune_admin[:show][:fields].reject{|f| column_names.include?(f)}
111
+ fields_to_add.each do |field|
112
+ columns << Kitsune::FauxColumn.new(field, :string)
113
+ end
114
+ columns
115
+ else
116
+ columns
117
+ end
118
+ end
119
+
105
120
  def columns_for_reflections
106
121
  if kitsune_admin[:reflections] && kitsune_admin[:reflections][:fields]
107
122
  kitsune_admin[:reflections][:fields].map do |field|
@@ -117,6 +132,16 @@ module Kitsune
117
132
  kitsune_admin[:sortable] && kitsune_admin[:sortable].include?(column.name.to_sym)
118
133
  end
119
134
 
135
+ def always?(column)
136
+ # move to column proxy
137
+ kitsune_admin[:always] && kitsune_admin[:always].include?(column.name.to_sym)
138
+ end
139
+
140
+ def column_linked?(column)
141
+ # move to column proxy
142
+ kitsune_admin[:linked] && kitsune_admin[:linked].include?(column.name.to_sym)
143
+ end
144
+
120
145
  def method_missing(method, *args, &block)
121
146
  @object.send(method, *args, &block)
122
147
  end
data/lib/kitsune/page.rb CHANGED
@@ -3,19 +3,32 @@ module Kitsune
3
3
  def self.included(model)
4
4
  model.class_eval do
5
5
  admin do
6
+ display :title, :layout, :parent_id, :url
6
7
  wysiwyg :body
7
- select :layout, Proc.new {Dir.glob(File.join(RAILS_ROOT, 'app', 'views', 'layouts', '*.html.haml')).map{|f| File.basename(f).split('.').first}}
8
+ select :layout, Proc.new {Dir.glob(File.join(RAILS_ROOT, 'app', 'views', 'layouts', '*.html.*')).map{|f| File.basename(f).split('.').first}}
8
9
  end
9
10
 
10
11
  before_save :update_url
11
12
  belongs_to :page, :foreign_key => "parent_id"
12
13
  belongs_to :parent, :class_name => 'Page'
14
+ validate :must_be_kitsune_route
15
+ validates_uniqueness_of :url
16
+
17
+ def title_for_url
18
+ CGI.escape(title.downcase.gsub(/\s+/, '-')).squeeze('-')
19
+ end
20
+
21
+ def url_for_page
22
+ parent ? parent.url_for_page + '/' + title_for_url : '/' + title_for_url
23
+ end
13
24
 
14
25
  def update_url
15
- unless url.present?
16
- write_attribute :url, CGI.escape(title.downcase.gsub(/\s+/, '-'))
17
- else
18
- write_attribute :url, CGI.escape(url)
26
+ write_attribute :url, (url.present? ? url : url_for_page)
27
+ end
28
+
29
+ def must_be_kitsune_route
30
+ unless ActionController::Routing::Routes.recognize_path(url.present? ? url : url_for_page)[:controller] == 'kitsune'
31
+ errors.add_to_base("URL is already being used")
19
32
  end
20
33
  end
21
34
  end
data/test/test_helper.rb CHANGED
@@ -3,7 +3,7 @@ $: << File.dirname(__FILE__)
3
3
 
4
4
  require 'rubygems'
5
5
  require 'test/unit'
6
- require 'activerecord'
6
+ require 'active_record'
7
7
  require 'shoulda'
8
8
  require 'kitsune'
9
9
  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.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - toastyapps
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-11 00:00:00 -05:00
13
+ date: 2010-01-15 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,7 @@ files:
70
70
  - app/views/admin/kitsune/records/edit.html.haml
71
71
  - app/views/admin/kitsune/records/index.html.haml
72
72
  - app/views/admin/kitsune/records/new.html.haml
73
+ - app/views/admin/kitsune/records/show.html.haml
73
74
  - app/views/admin/kitsune/sessions/new.html.haml
74
75
  - app/views/admin/kitsune/shared/_flashes.html.haml
75
76
  - app/views/kitsune/show.html.erb