tiny_cms 0.2.3 → 0.2.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.2.3
1
+ 0.2.4
@@ -1,6 +1,5 @@
1
1
  <div id='pages-tree'></div>
2
2
  <input type='button' id='new-node' value='<%= I18n.t 'pages.actions.new_page' %>' />
3
- <input type='button' id='new-section' value='<%= I18n.t 'pages.actions.new_section' %>' />
4
3
  <input type='button' id='destroy' value='<%= I18n.t 'pages.actions.destroy' %>' />
5
4
 
6
5
  <form id='page-creation' title='<%= I18n.t 'pages.actions.new_page' %>' style='display:none'>
@@ -10,11 +9,14 @@
10
9
  <input type='text' name='permalink' id='permalink' class='text ui-widget-content ui-corner-all' />
11
10
  </form>
12
11
 
12
+
13
13
  <script type='text/javascript' charset='utf-8'>
14
14
  jQuery(function(){
15
+ var translations = <%= I18n.t('pages', :default => {:actions => {}, :alerts => {}}).to_json %>
16
+
15
17
  jQuery("#pages-tree").pagesTree({
16
18
  controller : "<%= url_for :controller => params[:controller] %>",
17
- translations : <%= I18n.t('pages', :default => {:actions => {}, :alerts => {}}).to_json %>
19
+ translations : translations
18
20
  });
19
21
 
20
22
  jQuery("#page-creation").dialog({
@@ -23,17 +25,12 @@
23
25
  });
24
26
 
25
27
  jQuery("#new-node").click(function(){
26
- jQuery.tree.focused().create({ data : "page", attributes : {rel : 'page'}}, jQuery.tree.focused().selected || -1);
27
- return false;
28
- });
29
-
30
- jQuery("#new-section").click(function(){
31
- jQuery.tree.focused().create({ data : "section", attributes : {rel : ''}}, jQuery.tree.focused().selected || -1);
28
+ jQuery.tree.focused().create({ data : "page"}, jQuery.tree.focused().selected || -1);
32
29
  return false;
33
30
  });
34
31
 
35
32
  jQuery("#destroy").click(function(){
36
- if (confirm(opts.translations.actions.confirm))
33
+ if (confirm(translations.alerts.confirm))
37
34
  jQuery.tree.focused().remove();
38
35
  return false;
39
36
  });
@@ -6,7 +6,6 @@ class TinyCmsCreate<%= table_name.camelize %> < ActiveRecord::Migration
6
6
  t.integer :position
7
7
  t.string :title
8
8
  t.string :content
9
- t.boolean :is_page
10
9
 
11
10
  t.timestamps
12
11
  end
@@ -33,24 +33,12 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
33
33
  label : opts.translations.actions.new_page,
34
34
  icon : "create-page",
35
35
  visible : function (node, tree_obj) {
36
- if(node.length != 1 || node.attr('rel') == 'page') return false;
36
+ if(node.length != 1) return false;
37
37
  return tree_obj.check("creatable", node);
38
38
  },
39
39
 
40
40
  action : function (node, tree_obj) {
41
- tree_obj.create({ data : 'page', attributes : {rel : 'page'}}, tree_obj.get_node(node[0]));
42
- }
43
- },
44
-
45
- 'create-section' : {
46
- label : opts.translations.actions.new_section,
47
- icon : "create-secction",
48
- visible : function (node, tree_obj) {
49
- if(node.length != 1 || node.attr('rel') == 'page') return false;
50
- return tree_obj.check("creatable", node);
51
- },
52
- action : function (node, tree_obj) {
53
- tree_obj.create({ data : 'section', attributes : {rel : ''}}, tree_obj.get_node(node[0]));
41
+ tree_obj.create({data : 'page'}, tree_obj.get_node(node[0]));
54
42
  }
55
43
  },
56
44
 
@@ -82,7 +70,7 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
82
70
  visible : function (node, tree_obj) {
83
71
  var ok = true;
84
72
  $.each(node, function () {
85
- if(tree_obj.check("deletable", this) == false) {
73
+ if(tree_obj.check("deletable", this) === false) {
86
74
  ok = false;
87
75
  return false;
88
76
  }
@@ -95,22 +83,13 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
95
83
  $.each(node, function () {
96
84
  tree_obj.remove(this);
97
85
  });
98
- };
86
+ }
99
87
  }
100
88
  }
101
89
  }
102
90
  }
103
91
  },
104
92
 
105
- types : {
106
- "page" : {
107
- valid_children : "none",
108
- icon : {
109
- image : '/stylesheets/apple/file.png'
110
- }
111
- }
112
- },
113
-
114
93
  data : {
115
94
  type : 'json',
116
95
  async : true,
@@ -133,14 +112,15 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
133
112
  case 'inside':
134
113
  ref_node = $(ref);
135
114
  break;
136
- };
115
+ }
137
116
 
138
117
  var created_node = tree_obj.get(node);
139
118
  var page_data = created_node.data;
140
119
  $.extend(page_data, created_node.attributes);
141
120
 
142
- if (ref_node != -1)
121
+ if (ref_node != -1) {
143
122
  $.extend(page_data, {parent_id : ref_node.attr('data-node-id')});
123
+ }
144
124
 
145
125
  modalDialog = $('#page-creation');
146
126
 
@@ -208,8 +188,9 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
208
188
  });
209
189
 
210
190
  modalDialog.bind( "dialogclose", function(event, ui) {
211
- if(!valid)
191
+ if(!valid) {
212
192
  tree_obj.remove(node);
193
+ }
213
194
  }).dialog('open');
214
195
 
215
196
  return true;
@@ -218,7 +199,7 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
218
199
  onmove : function(node, ref, type, tree_obj, rollback){
219
200
  var ref_node, children, url, data;
220
201
  var child_ids = [];
221
-
202
+
222
203
  switch(type)
223
204
  {
224
205
  case 'before':
@@ -228,7 +209,7 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
228
209
  case 'inside':
229
210
  ref_node = tree_obj.parent(node);
230
211
  break;
231
- };
212
+ }
232
213
 
233
214
  if (ref_node == -1) {
234
215
  children = tree_obj.children(-1);
@@ -240,7 +221,7 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
240
221
  url = opts.controller + "/" + ref_node.attributes['data-node-id'] + '.json';
241
222
  $.each(children, function(index, value){ child_ids.push(value.attributes['data-node-id']); });
242
223
  }
243
-
224
+
244
225
  $.ajax({
245
226
  timeout : 3000,
246
227
  type : 'POST',
@@ -250,8 +231,9 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
250
231
  page : { child_ids : child_ids }
251
232
  },
252
233
  error : function(response, status){
253
- if(response.status == 422)
234
+ if(response.status == 422) {
254
235
  alert(opts.translations.alerts.duplicate_path);
236
+ }
255
237
  $.tree.rollback(rollback);
256
238
  },
257
239
  dataType : 'json'
@@ -291,8 +273,6 @@ document.write("<link rel='stylesheet' href='/stylesheets/apple/style.css' type=
291
273
  },
292
274
 
293
275
  onselect : function(node){
294
- if( !($(node).attr('rel') == 'section') )
295
- $('input#new-node, input#new-section').attr('disabled', true);
296
276
  $('input#destroy').removeAttr('disabled');
297
277
  },
298
278
 
@@ -28,7 +28,6 @@ module TinyCMS
28
28
  }
29
29
 
30
30
  model.named_scope :roots, :conditions => {:parent_id => nil}, :order => 'position'
31
- model.named_scope :pages, :conditions => {:is_page => true}
32
31
 
33
32
  model.belongs_to :parent, :class_name => model.to_s, :foreign_key => 'parent_id'
34
33
  model.has_many :children, :class_name => model.to_s, :foreign_key => 'parent_id', :order => 'position', :dependent => :destroy
@@ -36,11 +35,12 @@ module TinyCMS
36
35
  model.validates_presence_of :title
37
36
  model.validates_uniqueness_of :permalink, :scope => [:parent_id]
38
37
 
39
- model.validate :validates_no_children, :if => :is_page
40
38
  model.validates_associated :children
41
39
 
42
40
  model.before_validation :parameterize_permalink
43
41
 
42
+ model.send :attr_accessor, :rel # Does nothing but jstree sends attribute
43
+
44
44
  model.send :define_method, :children_with_position= do |array|
45
45
  # TODO: Too unefficient
46
46
  transaction { array.each_with_index{ |child, index| child.update_attributes! :position => index, :parent_id => id } } rescue nil
@@ -48,10 +48,6 @@ module TinyCMS
48
48
  end
49
49
  model.alias_method_chain :children=, :position
50
50
  end
51
-
52
- def rel= rel
53
- self.is_page = rel == 'page'
54
- end
55
51
 
56
52
  def siblings
57
53
  return [] unless parent_id
@@ -68,16 +64,11 @@ module TinyCMS
68
64
  end
69
65
 
70
66
  def to_hash
71
- {:attributes => {'data-node-id' => id, :rel => is_page ? 'page' : 'section', 'data-permalink' => permalink, 'data-path' => path}, :data => title, :children => children.map{ |c| c.to_hash } }
67
+ {:attributes => {'data-node-id' => id, 'data-permalink' => permalink, 'data-path' => path}, :data => title, :children => children.map{ |c| c.to_hash } }
72
68
  end
73
69
 
74
70
  def to_json opts = {}
75
71
  self.to_hash.to_json
76
72
  end
77
-
78
- private
79
- def validates_no_children
80
- errors.add(:base, "A page cannot have children") unless children.blank? # Todo: localize
81
- end
82
73
  end
83
74
  end
@@ -1,5 +1,6 @@
1
1
  module TinyCMS
2
2
  class PagesController < ApplicationController
3
+ unloadable
3
4
  helper_method :resource
4
5
 
5
6
  def index
@@ -41,7 +42,7 @@ module TinyCMS
41
42
  respond_to do |format|
42
43
  if resource.update_attributes params[resource_name]
43
44
  format.html { redirect_to resource }
44
- format.json { head :ok }
45
+ format.json { render :json => {} }
45
46
  else
46
47
  format.html { render 'tiny_cms/edit' }
47
48
  format.json { render :json => resource.errors, :status => :unprocessable_entity }
@@ -50,7 +51,11 @@ module TinyCMS
50
51
  end
51
52
 
52
53
  def reorder
53
- klass.reorder(params[:page]['child_ids']) ? head(:ok) : head(:unprocessable_entity)
54
+ if klass.reorder params[:page]['child_ids']
55
+ render :json => {}
56
+ else
57
+ render :json => {}, :status => :unprocessable_entity
58
+ end
54
59
  end
55
60
 
56
61
  def destroy
@@ -59,7 +64,7 @@ module TinyCMS
59
64
 
60
65
  respond_to do |format|
61
66
  format.html { redirect_to :controller => params[:controller], :action => 'index'}
62
- format.json { head :ok }
67
+ format.json { render :json => {} }
63
68
  end
64
69
  end
65
70
 
@@ -9,14 +9,9 @@ require 'rubygems'
9
9
  require 'test/unit'
10
10
  require 'shoulda'
11
11
  require 'factory_girl'
12
-
13
12
  require 'support/page_migration'
14
13
 
15
14
  Factory.define :page do |p|
16
15
  p.sequence(:title) { |i| "Node #{i}"}
17
16
  p.sequence(:permalink) { |i| "node_#{i}"}
18
- p.is_page true
19
- end
20
-
21
- class Test::Unit::TestCase
22
17
  end
@@ -11,7 +11,6 @@ ActiveRecord::Schema.define(:version => 1) do
11
11
  t.integer :position
12
12
  t.string :title
13
13
  t.string :content
14
- t.boolean :is_page
15
14
 
16
15
  t.timestamps
17
16
  end
@@ -3,13 +3,6 @@ require 'helper'
3
3
  class PageTest < Test::Unit::TestCase
4
4
  should_belong_to :parent
5
5
  should_have_many :children
6
-
7
- context 'attributes' do
8
- setup { @page = Factory :page, :rel => 'page' }
9
- should 'set is_page' do
10
- assert @page.is_page
11
- end
12
- end
13
6
 
14
7
  context 'children have positions' do
15
8
  setup do
@@ -64,7 +57,7 @@ class PageTest < Test::Unit::TestCase
64
57
  context 'invalid children' do
65
58
  setup do
66
59
  Page.destroy_all
67
- @root = Factory :page, :permalink => 'root', :position => 1, :is_page => false
60
+ @root = Factory :page, :permalink => 'root', :position => 1
68
61
  @root2 = Factory :page, :permalink => 'child', :position => 2
69
62
  @child = Factory :page, :permalink => 'child', :parent_id => @root.id, :position => 1
70
63
  @root.child_ids = [@root2.id, @child.id]
@@ -112,8 +105,8 @@ class PageTest < Test::Unit::TestCase
112
105
  context 'json generation' do
113
106
  setup do
114
107
  Page.destroy_all
115
- root = Factory.build :page, :is_page => false
116
- @pages = (1..5).map{ |i| Factory.build :page, :is_page => i == 5 }
108
+ root = Factory.build :page
109
+ @pages = (1..5).map{ |i| Factory.build :page }
117
110
 
118
111
  @pages.inject(root){ |parent, child| parent.children.push(child) and child }
119
112
  @pages.unshift root
@@ -124,7 +117,7 @@ class PageTest < Test::Unit::TestCase
124
117
 
125
118
  should 'override to json' do
126
119
  walk = lambda do |node|
127
- {:attributes => {'data-node-id' => node.id, :rel => node.is_page ? 'page' : 'section', 'data-path' => node.path, 'data-permalink' => node.permalink}, :data => node.title, :children => node.children.map{ |c| walk.call(c) }}
120
+ {:attributes => {'data-node-id' => node.id, 'data-path' => node.path, 'data-permalink' => node.permalink}, :data => node.title, :children => node.children.map{ |c| walk.call(c) }}
128
121
  end
129
122
  tree = walk.call @first
130
123
  assert_equal tree.to_json, @first.to_json
@@ -134,12 +127,12 @@ class PageTest < Test::Unit::TestCase
134
127
  context 'paths' do
135
128
  setup do
136
129
  Page.destroy_all
137
- root = Factory :page, :is_page => false
138
- @branch1 = (1..4).map{ |i| Factory :page, :is_page => i == 3 }
130
+ root = Factory :page
131
+ @branch1 = (1..4).map{ |i| Factory :page}
139
132
  @branch1.inject(root){ |parent, child| parent.children.push(child) and child }
140
133
  @branch1.unshift root
141
134
 
142
- @branch2 = (1..4).map{ |i| Factory :page, :is_page => i == 3 }
135
+ @branch2 = (1..4).map{ |i| Factory :page}
143
136
  @branch2.inject(root){ |parent, child| parent.children.push(child) and child }
144
137
  @branch2.unshift root
145
138
  end
@@ -223,18 +216,12 @@ class PageTest < Test::Unit::TestCase
223
216
  context 'validation' do
224
217
  should_validate_presence_of :title
225
218
 
226
- should 'not allow children if is page' do
227
- page = Factory.build :page, :is_page => true, :children => [Factory(:page)]
228
- assert_equal false, page.valid?
229
- assert_equal false, page.errors.on(:base).blank?
230
- end
231
-
232
219
  context 'permalink uniqueness' do
233
220
  setup do
234
221
  Page.destroy_all
235
222
  @page1 = Factory.build :page, :permalink => 'same'
236
223
  @page2 = Factory.build :page, :permalink => 'same'
237
- @page3 = Factory.build :page, :is_page => false
224
+ @page3 = Factory.build :page
238
225
  @page1.save(false)
239
226
  @page2.save(false)
240
227
  @page3.save(false)
@@ -248,7 +235,7 @@ class PageTest < Test::Unit::TestCase
248
235
  end
249
236
 
250
237
  # should 'allow duplicate if path is the same but one is not page' do
251
- # @page1.update_attribute :is_page, false
238
+ # @page1.update_attribute
252
239
  # assert_equal @page1.path, @page2.path
253
240
  # assert_equal @page1.permalink, @page2.permalink
254
241
  # @page1.save!
@@ -268,7 +255,7 @@ class PageTest < Test::Unit::TestCase
268
255
  end
269
256
 
270
257
  # should 'validate presence of permalink if is not page' do
271
- # page = Factory.build :page, :permalink => '', :is_page => false
258
+ # page = Factory.build :page, :permalink => ''
272
259
  # assert_equal false, page.valid?
273
260
  # assert_equal false, page.errors.on(:permalink).blank?
274
261
  # end
@@ -21,7 +21,7 @@ class PagesControllerTest < ActionController::TestCase
21
21
  context "as json" do
22
22
  setup do
23
23
  Page.destroy_all
24
- Factory :page, :children => [Factory(:page)], :is_page => false
24
+ Factory :page, :children => [Factory(:page)]
25
25
  get :index, :format => 'json'
26
26
  end
27
27
 
@@ -56,7 +56,7 @@ class PagesControllerTest < ActionController::TestCase
56
56
  end
57
57
 
58
58
  # should 'raise active record not found when node is not a page' do
59
- # @page.update_attribute :is_page, false
59
+ # @page.update_attribute
60
60
  # assert_raises ActiveRecord::RecordNotFound do
61
61
  # get :show, :path => @page.path.scan(/\w+/)
62
62
  # end
@@ -203,7 +203,7 @@ class PagesControllerTest < ActionController::TestCase
203
203
  context 'bad attributes' do
204
204
  setup do
205
205
  Page.destroy_all
206
- @root = Factory :page, :permalink => 'root', :position => 1, :is_page => false
206
+ @root = Factory :page, :permalink => 'root', :position => 1
207
207
  @root2 = Factory :page, :permalink => 'root2', :position => 2
208
208
  @child = Factory :page, :permalink => 'root', :parent_id => @root.id, :position => 1
209
209
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Macario
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-04 00:00:00 -05:00
17
+ date: 2010-08-18 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency