kitsune 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +5 -0
- data/Rakefile +21 -0
- data/app/controllers/admin/kitsune/models_controller.rb +13 -0
- data/app/controllers/admin/kitsune/pages_controller.rb +27 -0
- data/app/controllers/admin/kitsune/records_controller.rb +55 -0
- data/app/controllers/kitsune_controller.rb +5 -0
- data/app/helpers/admin/kitsune/records_helper.rb +19 -0
- data/app/views/admin/kitsune/models/_form.html.erb +16 -0
- data/app/views/admin/kitsune/models/index.html.erb +3 -0
- data/app/views/admin/kitsune/pages/_form.html.erb +13 -0
- data/app/views/admin/kitsune/pages/edit.html.erb +7 -0
- data/app/views/admin/kitsune/pages/index.html.erb +5 -0
- data/app/views/admin/kitsune/pages/new.html.erb +7 -0
- data/app/views/admin/kitsune/records/_form.html.erb +14 -0
- data/app/views/admin/kitsune/records/edit.html.erb +7 -0
- data/app/views/admin/kitsune/records/index.html.erb +36 -0
- data/app/views/admin/kitsune/records/new.html.erb +7 -0
- data/app/views/kitsune/show.html.erb +1 -0
- data/app/views/layouts/admin/kitsune.html.erb +15 -0
- data/config/kitsune_routes.rb +11 -0
- data/generators/kitsune/kitsune_generator.rb +26 -0
- data/generators/kitsune/lib/insert_commands.rb +31 -0
- data/generators/kitsune/templates/images/bg.jpg +0 -0
- data/generators/kitsune/templates/images/form-bg.gif +0 -0
- data/generators/kitsune/templates/images/grey-btn.png +0 -0
- data/generators/kitsune/templates/images/nicEditorIcons.gif +0 -0
- data/generators/kitsune/templates/javascripts/nicEdit.js +102 -0
- data/generators/kitsune/templates/migrations/create_pages.rb +14 -0
- data/generators/kitsune/templates/page.rb +3 -0
- data/generators/kitsune/templates/stylesheets/global.css +381 -0
- data/lib/kitsune.rb +37 -0
- data/lib/kitsune/active_record.rb +29 -0
- data/lib/kitsune/builder.rb +92 -0
- data/lib/kitsune/extensions/routes.rb +14 -0
- data/lib/kitsune/faux_column.rb +11 -0
- data/lib/kitsune/form_helper_ext.rb +12 -0
- data/lib/kitsune/inspector.rb +137 -0
- data/lib/kitsune/page.rb +18 -0
- data/rails/init.rb +3 -0
- metadata +102 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
module Kitsune
|
2
|
+
class TypeError < StandardError; end
|
3
|
+
class Builder
|
4
|
+
|
5
|
+
TYPES = [:check_box, :datetime_select, :password_field, :text_area, :text_field, :wysiwyg]
|
6
|
+
def initialize(resource, &block)
|
7
|
+
@resource = resource
|
8
|
+
self.instance_eval &block
|
9
|
+
end
|
10
|
+
|
11
|
+
def no_admin
|
12
|
+
@resource.kitsune_admin[:no_admin] = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def tabs(tabs)
|
16
|
+
@resource.kitsune_admin[:tabs] = tabs
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.generate(resource, &block)
|
20
|
+
Builder.new(resource, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def definitions
|
24
|
+
yield # should be it's own builder
|
25
|
+
end
|
26
|
+
|
27
|
+
def columns(type = nil)
|
28
|
+
@resource.columns
|
29
|
+
end
|
30
|
+
|
31
|
+
def sortable(*fields)
|
32
|
+
@resource.kitsune_admin[:sortable] ||= []
|
33
|
+
fields.each do |field|
|
34
|
+
@resource.kitsune_admin[:sortable] << field.to_sym
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def file(field)
|
39
|
+
add_definition(:file_field, field)
|
40
|
+
multipart
|
41
|
+
end
|
42
|
+
|
43
|
+
def multipart(value = true)
|
44
|
+
@resource.kitsune_admin[:multipart] = value
|
45
|
+
end
|
46
|
+
|
47
|
+
def select(field, options)
|
48
|
+
add_definition(:select, field, {:options => options})
|
49
|
+
end
|
50
|
+
|
51
|
+
def display_and_edit(*args)
|
52
|
+
display(*args)
|
53
|
+
edit(*args)
|
54
|
+
end
|
55
|
+
|
56
|
+
def display(*fields)
|
57
|
+
set_options_for_fields(:display, fields)
|
58
|
+
end
|
59
|
+
|
60
|
+
def edit(*fields)
|
61
|
+
set_options_for_fields(:edit, fields)
|
62
|
+
end
|
63
|
+
|
64
|
+
def no_edit(*fields)
|
65
|
+
set_options_for_fields(:no_edit, fields)
|
66
|
+
end
|
67
|
+
|
68
|
+
def method_missing(method, *args, &block)
|
69
|
+
if TYPES.include?(method)
|
70
|
+
add_definition(method, *args)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def add_definition(type, field, options = {})
|
76
|
+
@resource.kitsune_admin[:fields] ||= {}
|
77
|
+
@resource.kitsune_admin[:fields][field] = options.merge(:type => type)
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_options_for_fields(type, fields)
|
81
|
+
@resource.kitsune_admin[type] = {} unless @resource.kitsune_admin[type]
|
82
|
+
@resource.kitsune_admin[type][:fields] ||= []
|
83
|
+
fields.each do |field|
|
84
|
+
unless field.is_a?(Hash)
|
85
|
+
@resource.kitsune_admin[type][:fields] << field
|
86
|
+
else
|
87
|
+
@resource.kitsune_admin[type].merge!(field)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
if defined?(ActionController::Routing::RouteSet)
|
2
|
+
class ActionController::Routing::RouteSet
|
3
|
+
def load_routes_with_kitsune!
|
4
|
+
lib_path = File.dirname(__FILE__)
|
5
|
+
kitsune_routes = File.join(lib_path, *%w[.. .. .. config kitsune_routes.rb])
|
6
|
+
unless configuration_files.include?(kitsune_routes)
|
7
|
+
add_configuration_file(kitsune_routes)
|
8
|
+
end
|
9
|
+
load_routes_without_kitsune!
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method_chain :load_routes!, :kitsune
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
class FormBuilder
|
4
|
+
def wysiwyg(method, options={})
|
5
|
+
sanitized_object_name = @object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
6
|
+
sanitized_method_name = method.to_s.sub(/\?$/,"")
|
7
|
+
id = "#{sanitized_object_name}_#{sanitized_method_name}"
|
8
|
+
@template.send('text_area', @object_name, method, objectify_options(options.merge({:class => 'wysiwyg'}))) + @template.content_tag('script', "new nicEditor().panelInstance('#{id}');")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Kitsune
|
2
|
+
# Inspector is a proxy for adding additional methods. These should only be
|
3
|
+
# available within the Kitsune admin.
|
4
|
+
|
5
|
+
class Inspector
|
6
|
+
attr_reader :object
|
7
|
+
def initialize(object)
|
8
|
+
@object = object
|
9
|
+
@collection_label_methods = %w[to_label display_name full_name name title username login value to_s]
|
10
|
+
end
|
11
|
+
|
12
|
+
def tabs
|
13
|
+
kitsune_admin[:tabs]
|
14
|
+
end
|
15
|
+
|
16
|
+
def object_class
|
17
|
+
@object.class
|
18
|
+
end
|
19
|
+
|
20
|
+
def new_record(*args)
|
21
|
+
@object.new(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def columns(type = nil, include_pk = false)
|
25
|
+
unless type
|
26
|
+
kolumns = @object.columns.dup
|
27
|
+
else
|
28
|
+
kolumns = send("columns_for_#{type}") if respond_to?("columns_for_#{type}")
|
29
|
+
end
|
30
|
+
include_pk ? kolumns : kolumns.reject{|c| c.primary }
|
31
|
+
end
|
32
|
+
|
33
|
+
def columns_for_edit
|
34
|
+
kolumns = @object.columns.dup
|
35
|
+
if kitsune_admin[:no_edit] && kitsune_admin[:no_edit][:fields]
|
36
|
+
kolumns.reject{|c| kitsune_admin[:no_edit][:fields].include?(c.name.to_sym)}
|
37
|
+
elsif kitsune_admin[:edit] && kitsune_admin[:edit][:fields]
|
38
|
+
kolumns = kolumns.select{|c| kitsune_admin[:edit][:fields].include?(c.name.to_sym)}
|
39
|
+
kolumn_names = kolumns.map{|c| c.name.to_sym}
|
40
|
+
fields_to_add = kitsune_admin[:edit][:fields].reject{|f| kolumn_names.include?(f)}
|
41
|
+
fields_to_add.each do |field|
|
42
|
+
kolumns << Kitsune::FauxColumn.new(field, :string)
|
43
|
+
end
|
44
|
+
kolumns
|
45
|
+
else
|
46
|
+
kolumns
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def columns_for_display
|
51
|
+
columns = @object.columns.dup
|
52
|
+
if kitsune_admin[:display] && kitsune_admin[:display][:fields]
|
53
|
+
columns.select{|c| kitsune_admin[:display][:fields].include?(c.name.to_sym)}
|
54
|
+
else
|
55
|
+
columns
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def column_sortable(column)
|
60
|
+
# move to column proxy
|
61
|
+
kitsune_admin[:sortable] && kitsune_admin[:sortable].include?(column.name.to_sym)
|
62
|
+
end
|
63
|
+
|
64
|
+
def method_missing(method, *args, &block)
|
65
|
+
@object.send(method, *args, &block)
|
66
|
+
end
|
67
|
+
|
68
|
+
def form_type(column)
|
69
|
+
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]
|
71
|
+
elsif column.name =~ /_id$/
|
72
|
+
:select
|
73
|
+
else
|
74
|
+
case column.type
|
75
|
+
when :text then :text_area
|
76
|
+
when :datetime then :datetime_select
|
77
|
+
when :date then :date_select
|
78
|
+
when :time then :time_select
|
79
|
+
else :text_field
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def detect_label(collection)
|
85
|
+
@collection_label_methods.each do |label_name|
|
86
|
+
return label_name if collection.first.respond_to?(label_name)
|
87
|
+
end
|
88
|
+
'to_s'
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_association_class(column)
|
92
|
+
if @object.reflections[column.name.to_s.gsub(/_id$/,'').to_sym]
|
93
|
+
if @object.reflections[column.name.to_s.gsub(/_id$/,'').to_sym].options && @object.reflections[column.name.to_s.gsub(/_id$/,'').to_sym].options[:class_name]
|
94
|
+
@object.reflections[column.name.to_s.gsub(/_id$/,'').to_sym].options[:class_name].constantize
|
95
|
+
else
|
96
|
+
return column.name.to_s.gsub(/_id$/,'').classify.constantize
|
97
|
+
end
|
98
|
+
else
|
99
|
+
# foreign key
|
100
|
+
@object.reflections.each do |key, reflection|
|
101
|
+
if reflection.options && reflection.options[:foreign_key] && reflection.options[:foreign_key] == column.name.to_s
|
102
|
+
if reflection.options && reflection.options[:class_name]
|
103
|
+
reflection.options[:class_name].constantize
|
104
|
+
else
|
105
|
+
return key.to_s.classify.constantize
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def form_options_for(record)
|
113
|
+
options = {:method => method_for_record(record)}
|
114
|
+
if kitsune_admin[:multipart]
|
115
|
+
options.merge!({:html => {:multipart => true}})
|
116
|
+
end
|
117
|
+
options
|
118
|
+
end
|
119
|
+
|
120
|
+
def method_for_record(record)
|
121
|
+
record.new_record? ? :post : :put
|
122
|
+
end
|
123
|
+
|
124
|
+
def options_for(column)
|
125
|
+
if column.name =~ /_id$/
|
126
|
+
id = :id
|
127
|
+
collection = find_association_class(column).all
|
128
|
+
name = detect_label(collection)
|
129
|
+
[collection.map { |r| [ r.send(name), r.send(id) ] }, {:include_blank => true}]
|
130
|
+
else
|
131
|
+
options = {}
|
132
|
+
options[:size] = '80x10' if [:text_area, :wysiwyg].include?(form_type(column))
|
133
|
+
[options]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/lib/kitsune/page.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kitsune
|
2
|
+
module Page
|
3
|
+
def self.included(model)
|
4
|
+
model.class_eval do
|
5
|
+
admin do
|
6
|
+
wysiwyg :body
|
7
|
+
end
|
8
|
+
|
9
|
+
before_save :update_url
|
10
|
+
belongs_to :page, :foreign_key => "parent_id"
|
11
|
+
|
12
|
+
def update_url
|
13
|
+
write_attribute :url, title
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitsune
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Mongeau <matt@toastyapps.com>
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-23 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mislav-will_paginate
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.11
|
24
|
+
version:
|
25
|
+
description: Integrated Rails Content Management System.
|
26
|
+
email: matt@toastyapps.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- Rakefile
|
35
|
+
- README.textile
|
36
|
+
- app/controllers/admin/kitsune/models_controller.rb
|
37
|
+
- app/controllers/admin/kitsune/pages_controller.rb
|
38
|
+
- app/controllers/admin/kitsune/records_controller.rb
|
39
|
+
- app/controllers/kitsune_controller.rb
|
40
|
+
- app/helpers/admin/kitsune/records_helper.rb
|
41
|
+
- app/views/admin/kitsune/models/_form.html.erb
|
42
|
+
- app/views/admin/kitsune/models/index.html.erb
|
43
|
+
- app/views/admin/kitsune/pages/_form.html.erb
|
44
|
+
- app/views/admin/kitsune/pages/edit.html.erb
|
45
|
+
- app/views/admin/kitsune/pages/index.html.erb
|
46
|
+
- app/views/admin/kitsune/pages/new.html.erb
|
47
|
+
- app/views/admin/kitsune/records/_form.html.erb
|
48
|
+
- app/views/admin/kitsune/records/edit.html.erb
|
49
|
+
- app/views/admin/kitsune/records/index.html.erb
|
50
|
+
- app/views/admin/kitsune/records/new.html.erb
|
51
|
+
- app/views/kitsune/show.html.erb
|
52
|
+
- app/views/layouts/admin/kitsune.html.erb
|
53
|
+
- config/kitsune_routes.rb
|
54
|
+
- generators/kitsune/kitsune_generator.rb
|
55
|
+
- generators/kitsune/lib/insert_commands.rb
|
56
|
+
- generators/kitsune/templates/images/bg.jpg
|
57
|
+
- generators/kitsune/templates/images/form-bg.gif
|
58
|
+
- generators/kitsune/templates/images/grey-btn.png
|
59
|
+
- generators/kitsune/templates/images/nicEditorIcons.gif
|
60
|
+
- generators/kitsune/templates/javascripts/nicEdit.js
|
61
|
+
- generators/kitsune/templates/migrations/create_pages.rb
|
62
|
+
- generators/kitsune/templates/page.rb
|
63
|
+
- generators/kitsune/templates/stylesheets/global.css
|
64
|
+
- lib/kitsune/active_record.rb
|
65
|
+
- lib/kitsune/builder.rb
|
66
|
+
- lib/kitsune/extensions/routes.rb
|
67
|
+
- lib/kitsune/faux_column.rb
|
68
|
+
- lib/kitsune/form_helper_ext.rb
|
69
|
+
- lib/kitsune/inspector.rb
|
70
|
+
- lib/kitsune/page.rb
|
71
|
+
- lib/kitsune.rb
|
72
|
+
- rails/init.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/toastyapps/kitsune
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
requirements:
|
95
|
+
- mislav-will_paginate
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.3.4
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Integrated Rails Content Management System.
|
101
|
+
test_files: []
|
102
|
+
|