kitsune 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/app/controllers/admin/kitsune/kitsune_controller.rb +1 -1
- data/app/controllers/admin/kitsune/media_controller.rb +27 -0
- data/app/controllers/admin/kitsune/records_controller.rb +22 -18
- data/app/helpers/admin/kitsune/records_helper.rb +8 -1
- data/app/views/admin/kitsune/media/new.html.erb +49 -0
- data/app/views/admin/kitsune/records/_form.html.haml +1 -0
- data/app/views/admin/kitsune/shared/_flashes.html.haml +6 -0
- data/app/views/layouts/admin/kitsune.html.erb +17 -2
- data/config/kitsune_routes.rb +1 -0
- data/generators/kitsune/kitsune_generator.rb +12 -7
- data/generators/kitsune/templates/javascripts/upload_maker.js +19 -0
- data/generators/kitsune/templates/stylesheets/global.css +4 -0
- data/lib/kitsune.rb +1 -1
- data/lib/kitsune/active_record.rb +3 -1
- data/lib/kitsune/builder.rb +44 -4
- data/lib/kitsune/form_helper_ext.rb +12 -1
- data/lib/kitsune/inspector.rb +8 -0
- metadata +6 -2
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.
|
5
|
+
gem_spec.version = "0.0.17"
|
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,27 @@
|
|
1
|
+
class Admin::Kitsune::MediaController < Admin::Kitsune::KitsuneController
|
2
|
+
layout 'admin/kitsune'
|
3
|
+
|
4
|
+
helper 'admin/kitsune/records'
|
5
|
+
|
6
|
+
before_filter :load_model
|
7
|
+
|
8
|
+
def new
|
9
|
+
@parent_instance = @parent.new_record
|
10
|
+
@media = @model.new_record
|
11
|
+
render :layout => false
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@media = @model.new_record
|
16
|
+
@upload = @model.new_record
|
17
|
+
@parent_instance = @parent.new_record
|
18
|
+
@upload.update_attribute(@parent.kitsune_admin[:media].values.first, params['image'])
|
19
|
+
render 'new', :layout => false
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def load_model
|
24
|
+
@parent = Kitsune::Inspector.new(params[:model_id].constantize) if params[:model_id]
|
25
|
+
@model = Kitsune::Inspector.new(params[:id].constantize) if params[:id]
|
26
|
+
end
|
27
|
+
end
|
@@ -5,7 +5,7 @@ class Admin::Kitsune::RecordsController < Admin::Kitsune::KitsuneController
|
|
5
5
|
before_filter :load_record
|
6
6
|
|
7
7
|
def index
|
8
|
-
order, @sort_param, @sort_dir =
|
8
|
+
order, @sort_param, @sort_dir = @model.order_by, nil, nil
|
9
9
|
if params[:sort]
|
10
10
|
@sort_param = params[:sort]
|
11
11
|
@sort_dir = params[:sort_dir]
|
@@ -19,24 +19,28 @@ class Admin::Kitsune::RecordsController < Admin::Kitsune::KitsuneController
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def create
|
22
|
-
if
|
23
|
-
|
24
|
-
@record = sti_model.new_record(params[params[:model_id].underscore])
|
22
|
+
if request.xhr?
|
23
|
+
render :text => "Foo"
|
25
24
|
else
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
25
|
+
if @model.is_sti? && params[params[:model_id].underscore][@model.sti_column].present?
|
26
|
+
sti_model = Kitsune::Inspector.new(params[params[:model_id].underscore].delete(@model.sti_column).constantize)
|
27
|
+
@record = sti_model.new_record(params[params[:model_id].underscore])
|
28
|
+
else
|
29
|
+
@record = @model.new_record(params[params[:model_id].underscore])
|
30
|
+
end
|
31
|
+
if @record.save
|
32
|
+
flash[:notice] = "Record Saved"
|
33
|
+
if params[:redirect]
|
34
|
+
klass = params[:redirect].gsub(/_id$/, '').classify.constantize
|
35
|
+
record = klass.find(params[:redirect_id])
|
36
|
+
redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => klass.to_s, :id => params[:redirect_id], :action => :edit)
|
37
|
+
else
|
38
|
+
redirect_to url_for(:controller => 'admin/kitsune/records', :model_id => @model.class_name)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
flash[:notice] = "Could not save record"
|
42
|
+
render 'new'
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
@@ -5,13 +5,20 @@ module Admin::Kitsune::RecordsHelper
|
|
5
5
|
|
6
6
|
def sort_link_to(resource, column)
|
7
7
|
if resource.column_sortable(column)
|
8
|
+
ascending = false
|
9
|
+
unless params[:sort]
|
10
|
+
if resource.order_by_hash && resource.order_by_hash.keys.include?(column.name.to_sym)
|
11
|
+
params[:sort] = column.name
|
12
|
+
params[:sort_dir] = resource.order_by_hash[column.name.to_sym].to_s.upcase
|
13
|
+
end
|
14
|
+
end
|
8
15
|
ascending = params[:sort] == column.name && params[:sort_dir] == 'DESC'
|
9
16
|
options = {
|
10
17
|
:model => resource.object,
|
11
18
|
:sort => column.name,
|
12
19
|
:sort_dir => (ascending ? 'ASC' : 'DESC')
|
13
20
|
}
|
14
|
-
link_to column.name.to_s.titleize + (ascending ? ' ↓' : ' ↑'), options
|
21
|
+
link_to column.name.to_s.titleize + (ascending ? ' ↓' : (params[:sort] == column.name ? ' ↑' : ' ↕')), options
|
15
22
|
else
|
16
23
|
column.name.to_s.titleize
|
17
24
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
|
7
|
+
<%= javascript_include_tag 'kitsune/jquery.js', 'kitsune/kitsune_jquery.js', 'kitsune/upload_maker.js' %>
|
8
|
+
<script type="text/javascript">
|
9
|
+
$(document).ready(function() {
|
10
|
+
//Get the parent window
|
11
|
+
up = window.parent.document;
|
12
|
+
<% if @upload %>
|
13
|
+
var destination = '<%= params['destination'] %>'
|
14
|
+
//Update value
|
15
|
+
$('#' + destination, up).val('<%= @upload.send(@parent.kitsune_admin[:media].values.first).url %>');
|
16
|
+
//Trigger select
|
17
|
+
$('#' + destination, up).focus();
|
18
|
+
<% end %>
|
19
|
+
})
|
20
|
+
</script>
|
21
|
+
</head>
|
22
|
+
<body style="background-color:transparent; margin:0px; padding:0px; overflow:hidden;">
|
23
|
+
<% form_for(@parent_instance, :url => url_for_record(@parent_instance).gsub(/records/, 'media')+"?id=#{@media.class.to_s}", :html => {:multipart => true, :id => "upload_image_form"}) do |form| %>
|
24
|
+
<input type="hidden" name="destination" value="<%= params['destination'] %>">
|
25
|
+
<div id="controls">
|
26
|
+
<input type="hidden" name="domain" value="data"/>
|
27
|
+
|
28
|
+
<div style="font:normal 11px 'Lucida Grande',Verdana; color:#aaa;
|
29
|
+
text-decoration:none; cursor:pointer; position:absolute;
|
30
|
+
right:0px; top:0px; height:16px; line-height:16px;">+ Upload photo</div>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<div
|
34
|
+
style="position:absolute; right:0px; top:0px;
|
35
|
+
width:100px; height:24px;
|
36
|
+
filter:alpha(opacity=0); -moz-opacity:0; opacity:0; overflow:hidden;"><input
|
37
|
+
type="file" id="image" name="image"
|
38
|
+
style="cursor:pointer; height:24px; position:absolute;
|
39
|
+
right:0px; top:0px;"
|
40
|
+
onchange="document.getElementById('upload_image_form').submit();
|
41
|
+
document.getElementById('controls').style.display = 'none';
|
42
|
+
document.getElementById('loader').style.display = 'inline';"/></div>
|
43
|
+
|
44
|
+
<img src="http://assets.tumblr.com/images/bookmarklet_loader.gif" id="loader" style="display:none; width:16px;
|
45
|
+
height:16px; position:absolute; top:0px; right:0px;"/>
|
46
|
+
<% end %>
|
47
|
+
</body>
|
48
|
+
|
49
|
+
</html>
|
@@ -2,12 +2,26 @@
|
|
2
2
|
<html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
|
3
3
|
<head>
|
4
4
|
<title>Kitsune CMS</title>
|
5
|
-
<%= javascript_include_tag 'kitsune/jquery.js', 'kitsune/kitsune_jquery.js' %>
|
5
|
+
<%= javascript_include_tag 'kitsune/jquery.js', 'kitsune/kitsune_jquery.js', 'kitsune/upload_maker.js' %>
|
6
6
|
<%= stylesheet_link_tag 'kitsune/global.css' %>
|
7
7
|
<!--[if IE]>
|
8
8
|
<%= stylesheet_link_tag 'kitsune/ie.css' %>
|
9
9
|
<![endif]-->
|
10
|
-
<%= javascript_include_tag 'kitsune/
|
10
|
+
<%= javascript_include_tag 'kitsune/tiny_mce/tiny_mce.js' %>
|
11
|
+
<script type='text/javascript'>
|
12
|
+
tinyMCE.init({
|
13
|
+
plugins: "iespell",
|
14
|
+
theme: "advanced",
|
15
|
+
width: "650px",
|
16
|
+
height: "500px",
|
17
|
+
theme_advanced_buttons1 : "bold,italic,strikethrough,|,bullist,numlist,|,outdent,indent,|,image,link,unlink,|,code",
|
18
|
+
theme_advanced_buttons2 : "",
|
19
|
+
theme_advanced_buttons3 : "",
|
20
|
+
theme_advanced_toolbar_location : "top",
|
21
|
+
convert_urls : false
|
22
|
+
});
|
23
|
+
</script>
|
24
|
+
<%= yield :head %>
|
11
25
|
</head>
|
12
26
|
<body>
|
13
27
|
<div id='content'>
|
@@ -15,6 +29,7 @@
|
|
15
29
|
<h1><%= link_to 'Kitsune CMS', :controller => 'admin/kitsune/models' %></h1>
|
16
30
|
<a href='/' class='view'>View Site</a>
|
17
31
|
</div>
|
32
|
+
<%= render "admin/kitsune/shared/flashes" %>
|
18
33
|
<div class='kitsune_container'>
|
19
34
|
<div class='kitsune_right_container'>
|
20
35
|
<div class='kitsune_right wrapper'>
|
data/config/kitsune_routes.rb
CHANGED
@@ -3,19 +3,24 @@ class KitsuneGenerator < Rails::Generator::Base
|
|
3
3
|
|
4
4
|
def initialize(runtime_args, runtime_options = {})
|
5
5
|
@versioned = runtime_args.delete("--versioned")
|
6
|
+
@include_pages = runtime_args.delete("--include-page-model")
|
7
|
+
@include_users = runtime_args.delete("--include-user-model")
|
6
8
|
super
|
7
9
|
end
|
8
10
|
|
9
11
|
def manifest
|
10
12
|
record do |m|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
if !!@include_pages
|
14
|
+
page_model = "app/models/page.rb"
|
15
|
+
if File.exists?(page_model)
|
16
|
+
m.insert_into page_model, "include Kitsune::Page"
|
17
|
+
else
|
18
|
+
m.directory File.join("app", "models")
|
19
|
+
m.file "page.rb", page_model
|
20
|
+
m.migration_template "migrations/create_pages.rb", 'db/migrate', :migration_file_name => "kitsune_create_pages"
|
21
|
+
end
|
18
22
|
end
|
23
|
+
|
19
24
|
if !!@versioned
|
20
25
|
Rails::Generator::Scripts::Generate.new.run(['vestal_versions_migration'])
|
21
26
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$.fn.upload_maker = function(destination) {
|
2
|
+
$(this).each(function() {
|
3
|
+
//Get some vars
|
4
|
+
var id = $(this).attr('id');
|
5
|
+
var image_input_id = id + '_image_url';
|
6
|
+
//write the iframe
|
7
|
+
$(this).before('<iframe src="'+destination+'?destination=' + image_input_id +'" frameborder="0"></iframe>');
|
8
|
+
//write hidden input
|
9
|
+
$(this).after('<input id="' + image_input_id +'" name="' + image_input_id +'" style="position:absolute;left:-9999em" />');
|
10
|
+
$('#' + image_input_id).focus(function() {
|
11
|
+
var url = $(this).val();
|
12
|
+
if (tinyMCE && (ed = tinyMCE.get(id))) {
|
13
|
+
ed.execCommand('mceInsertContent', false, '<img src="' + url + '" alt="' + url + '" />');
|
14
|
+
} else {
|
15
|
+
insertTag(id, '<img src="' + url + '" alt="' + url + '" />');
|
16
|
+
}
|
17
|
+
});
|
18
|
+
})
|
19
|
+
}
|
@@ -307,6 +307,10 @@ button.submitBtn:hover {
|
|
307
307
|
color: #fff;
|
308
308
|
}
|
309
309
|
|
310
|
+
#flash_messages {padding:0px;}
|
311
|
+
.flash_notice {background:green; padding:5px; color:white;}
|
312
|
+
.flash_error {background:red; padding:5px; color:white;}
|
313
|
+
|
310
314
|
.kitsune_container {
|
311
315
|
background:url('/images/kitsune/content-bg.gif') repeat-x left top;
|
312
316
|
padding-top: 20px;
|
data/lib/kitsune.rb
CHANGED
data/lib/kitsune/builder.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Kitsune
|
2
2
|
class TypeError < StandardError; end
|
3
3
|
class Builder
|
4
|
-
|
4
|
+
|
5
5
|
TYPES = [:check_box, :datetime_select, :password_field, :text_area, :text_field, :wysiwyg]
|
6
6
|
def initialize(resource, &block)
|
7
7
|
@resource = resource
|
@@ -16,10 +16,17 @@ module Kitsune
|
|
16
16
|
@resource.kitsune_admin[:name] = name
|
17
17
|
end
|
18
18
|
|
19
|
+
def media media
|
20
|
+
@resource.kitsune_admin[:media] = media
|
21
|
+
end
|
22
|
+
|
19
23
|
def no_menu
|
20
24
|
no_admin
|
21
25
|
end
|
22
26
|
|
27
|
+
def order_by(order)
|
28
|
+
@resource.kitsune_admin[:order_by] = order
|
29
|
+
end
|
23
30
|
|
24
31
|
def versioned
|
25
32
|
@resource.send(:versioned)
|
@@ -78,6 +85,14 @@ module Kitsune
|
|
78
85
|
add :select, field, {:options => options}
|
79
86
|
end
|
80
87
|
|
88
|
+
def string(field)
|
89
|
+
add :text_field, field
|
90
|
+
end
|
91
|
+
|
92
|
+
def text(field)
|
93
|
+
add :text_area, field
|
94
|
+
end
|
95
|
+
|
81
96
|
def sti(field, options = {})
|
82
97
|
add :sti, field, {:options => options}
|
83
98
|
is_sti field
|
@@ -94,13 +109,36 @@ module Kitsune
|
|
94
109
|
end
|
95
110
|
|
96
111
|
def display(*fields)
|
97
|
-
|
112
|
+
fields.each do |field|
|
113
|
+
if field.is_a?(Hash)
|
114
|
+
field.each do |key, value|
|
115
|
+
set :display, key
|
116
|
+
set_attributes(key, value)
|
117
|
+
end
|
118
|
+
else
|
119
|
+
set :display, field
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_attributes(field, attributes)
|
125
|
+
[attributes].flatten.each do |attribute|
|
126
|
+
send(attribute.to_sym, field)
|
127
|
+
end
|
98
128
|
end
|
99
129
|
|
100
130
|
def edit(*fields)
|
101
131
|
fields.each do |field|
|
102
|
-
|
103
|
-
|
132
|
+
if field.is_a?(Hash)
|
133
|
+
field.each do |key, value|
|
134
|
+
type = @resource.reflections[key.to_sym] ? :reflections : :edit
|
135
|
+
set(type, key)
|
136
|
+
set_attributes(key, value)
|
137
|
+
end
|
138
|
+
else
|
139
|
+
type = @resource.reflections[field.to_sym] ? :reflections : :edit
|
140
|
+
set type, field
|
141
|
+
end
|
104
142
|
end
|
105
143
|
end
|
106
144
|
|
@@ -111,6 +149,8 @@ module Kitsune
|
|
111
149
|
def method_missing(method, *args, &block)
|
112
150
|
if TYPES.include?(method)
|
113
151
|
add method, *args
|
152
|
+
else
|
153
|
+
raise Exception, "THIS IS WRONG@! #{method.to_s}"
|
114
154
|
end
|
115
155
|
end
|
116
156
|
|
@@ -5,7 +5,18 @@ module ActionView
|
|
5
5
|
sanitized_object_name = @object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
6
6
|
sanitized_method_name = method.to_s.sub(/\?$/,"")
|
7
7
|
id = "#{sanitized_object_name}_#{sanitized_method_name}"
|
8
|
-
|
8
|
+
if @object.kitsune_admin[:media]
|
9
|
+
@template.content_for(:head) do
|
10
|
+
@template.capture do
|
11
|
+
"<script>
|
12
|
+
$(function() {
|
13
|
+
$('textarea.wysiwyg').upload_maker('#{@template.url_for({:id => @object.kitsune_admin[:media].keys.first.to_s.classify, :action=>"new", :controller=>"admin/kitsune/media"})}');
|
14
|
+
})
|
15
|
+
</script>"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
@template.send('text_area', @object_name, method, objectify_options(options.merge({:class => 'wysiwyg'}))) + @template.content_tag('script', "tinyMCE.execCommand('mceAddControl', true, '#{id}');")
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
data/lib/kitsune/inspector.rb
CHANGED
@@ -13,6 +13,14 @@ module Kitsune
|
|
13
13
|
kitsune_admin[:name] || @object.to_s.pluralize
|
14
14
|
end
|
15
15
|
|
16
|
+
def order_by
|
17
|
+
order_by_hash ? order_by_hash.map{|k,v| "#{k} #{v}"}.join(' ') : nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def order_by_hash
|
21
|
+
kitsune_admin[:order_by] || nil
|
22
|
+
end
|
23
|
+
|
16
24
|
def category
|
17
25
|
kitsune_admin[:category] || nil
|
18
26
|
end
|
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.
|
4
|
+
version: 0.0.17
|
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-12-
|
12
|
+
date: 2009-12-10 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,11 +45,13 @@ files:
|
|
45
45
|
- README.textile
|
46
46
|
- app/controllers/admin/kitsune/application_controller.rb
|
47
47
|
- app/controllers/admin/kitsune/kitsune_controller.rb
|
48
|
+
- app/controllers/admin/kitsune/media_controller.rb
|
48
49
|
- app/controllers/admin/kitsune/models_controller.rb
|
49
50
|
- app/controllers/admin/kitsune/pages_controller.rb
|
50
51
|
- app/controllers/admin/kitsune/records_controller.rb
|
51
52
|
- app/controllers/kitsune_controller.rb
|
52
53
|
- app/helpers/admin/kitsune/records_helper.rb
|
54
|
+
- app/views/admin/kitsune/media/new.html.erb
|
53
55
|
- app/views/admin/kitsune/models/index.html.haml
|
54
56
|
- app/views/admin/kitsune/pages/_form.html.erb
|
55
57
|
- app/views/admin/kitsune/pages/edit.html.erb
|
@@ -60,6 +62,7 @@ files:
|
|
60
62
|
- app/views/admin/kitsune/records/edit.html.haml
|
61
63
|
- app/views/admin/kitsune/records/index.html.haml
|
62
64
|
- app/views/admin/kitsune/records/new.html.haml
|
65
|
+
- app/views/admin/kitsune/shared/_flashes.html.haml
|
63
66
|
- app/views/kitsune/show.html.erb
|
64
67
|
- app/views/layouts/admin/kitsune.html.erb
|
65
68
|
- config/kitsune_routes.rb
|
@@ -77,6 +80,7 @@ files:
|
|
77
80
|
- generators/kitsune/templates/javascripts/jquery.js
|
78
81
|
- generators/kitsune/templates/javascripts/kitsune_jquery.js
|
79
82
|
- generators/kitsune/templates/javascripts/nicEdit.js
|
83
|
+
- generators/kitsune/templates/javascripts/upload_maker.js
|
80
84
|
- generators/kitsune/templates/migrations/create_pages.rb
|
81
85
|
- generators/kitsune/templates/page.rb
|
82
86
|
- generators/kitsune/templates/README
|