adminpanel 1.2.1 → 1.2.2

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.
@@ -3,8 +3,11 @@ require 'carrierwave/orm/activerecord'
3
3
  module Adminpanel
4
4
  class Section < ActiveRecord::Base
5
5
  attr_accessible :description, :has_image, :key, :page, :name, :has_description, :images_attributes
6
+
6
7
  has_many :images, :foreign_key => "foreign_key", :conditions => { :model => "Section" }
7
8
  accepts_nested_attributes_for :images, :allow_destroy => true
9
+
10
+
8
11
  validates_length_of :description, :minimum => 10, :maximum => 10, :on => :update, :if => lambda{|section| section.key == "telephone"}
9
12
  validates_presence_of :description, :minimum => 9, :on => :update, :if => lambda{|section| section.has_description == true}
10
13
  validates :description, :numericality => { :only_integer => true }, :on => :update, :if => lambda{|section| section.key == "telephone"}
@@ -20,4 +23,4 @@ module Adminpanel
20
23
  "Section"
21
24
  end
22
25
  end
23
- end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Adminpanel
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -1,75 +1,125 @@
1
- namespace :adminpanel do
2
- desc "Populate database of adminpanel model"
1
+ namespace :adminpanel do
2
+ desc "Interact with adminpanel models :D"
3
+
4
+ task :section, [:section, :name, :type] => :environment do |t, args|
5
+ args.with_defaults(:section => "home", :name => "greeting", :type => "wysiwyg")
6
+ puts "Creating #{args[:name]} in #{args[:section]} section"
7
+
8
+ s = Adminpanel::Section.new(
9
+ :name => args[:name].titleize,
10
+ :has_description => false,
11
+ :description => "",
12
+ :key => args[:name].underscore,
13
+ :page => args[:section],
14
+ :has_image => false
15
+ )
16
+
17
+ args[:type].split(" ").each do |type|
18
+ case type
19
+ when "wysiwyg" || "description"
20
+ s.has_description = true
21
+ when "images"
22
+ s.has_image = true
23
+ end
24
+ end
25
+ s.save
26
+ end
3
27
 
4
- task :populate, [:times, :model, :attributes] => :environment do |t, args|
28
+ task :dump_sections => :environment do |t|
29
+ puts "Dumping adminpanel_sections table into db/seeds.rb"
30
+ File.open("db/seeds.rb", "w") do |f|
31
+ f << "Adminpanel::Section.delete_all\n"
32
+ Adminpanel::Section.all.each do |section|
33
+ f << "#{creation_command(section)}"
34
+ end
5
35
 
6
- puts "Generating #{args[:times]} records of #{args[:model]}"
36
+ end
7
37
 
8
- model = "adminpanel/#{args[:model]}".classify.constantize
38
+ end
9
39
 
10
- attributes = args[:attributes].split(" ")
40
+ task :dump => :dump_sections
11
41
 
12
- init_variables
42
+ task :populate, [:times, :model, :attributes] => :environment do |t, args|
13
43
 
14
- has_image = false
15
- args[:times].to_i.times do |time|
16
- instance = model.new
17
- attributes.each do |attribute|
18
- field = attribute.split(":").first
19
- type = attribute.split(":").second
44
+ puts "Generating #{args[:times]} records of #{args[:model]}"
20
45
 
21
- case type
22
- when "name" #generate a name
23
- value = generate_name
46
+ model = "adminpanel/#{args[:model]}".classify.constantize
24
47
 
25
- when "category" || "category_name" #generate a category name
26
- value = @things.sample.pluralize
48
+ attributes = args[:attributes].split(" ")
27
49
 
28
- when "lorem_name" || "sentence"
29
- value = generate_lorem_name #lorem random short sentence
50
+ init_variables
30
51
 
31
- when "description" || "lorem" #large paragraph.
32
- value = generate_lorem
52
+ has_image = false
53
+ args[:times].to_i.times do |time|
54
+ instance = model.new
55
+ attributes.each do |attribute|
56
+ field = attribute.split(":").first
57
+ type = attribute.split(":").second
33
58
 
34
- when "number" #generate a number
35
- value = [*1..5000].sample
59
+ case type
60
+ when "name" #generate a name
61
+ value = generate_name
36
62
 
37
- when "id" #assign field_id it to a random instance of Adminpanel::field
38
- value = "adminpanel/#{field}".classify.constantize.order("RAND()").first.id
39
- field = "#{field}_id"
63
+ when "category" || "category_name" #generate a category name
64
+ value = @things.sample.pluralize
40
65
 
41
- when "email" #generates a random email
42
- value = generate_email
66
+ when "lorem_name" || "sentence"
67
+ value = generate_lorem_name #lorem random short sentence
43
68
 
44
- when "image" #force an image...
45
- has_image = true
46
- @file_url = "http://placehold.it/#{field}"
69
+ when "description" || "lorem" #large paragraph.
70
+ value = generate_lorem
47
71
 
48
- else #no type
49
- value = "#{time + 1} Lorem ipsum dolor sit amec"
72
+ when "number" #generate a number
73
+ value = [*1..5000].sample
50
74
 
51
- end
75
+ when "id" #assign field_id it to a random instance of Adminpanel::field
76
+ value = "adminpanel/#{field}".classify.constantize.order("RAND()").first.id
77
+ field = "#{field}_id"
52
78
 
53
- if(type != "image")
54
- instance.send("#{field}=", value)
55
- end
56
- end
79
+ when "email" #generates a random email
80
+ value = generate_email
57
81
 
58
- instance.save
82
+ when "image" #force an image...
83
+ has_image = true
84
+ @file_url = "http://placehold.it/#{field}"
59
85
 
60
- change_update_date(instance)
86
+ else #no type
87
+ value = "#{time + 1} Lorem ipsum dolor sit amec"
61
88
 
62
- if(has_image) #forcing the image into the db
63
- create_image_associated_to_id(instance.id)
64
89
  end
65
90
 
91
+ if(type != "image")
92
+ instance.send("#{field}=", value)
93
+ end
94
+ end
95
+
96
+ instance.save
97
+
98
+ change_update_date(instance)
99
+
100
+ if(has_image) #forcing the image into the db
101
+ create_image_associated_to_id(instance.id)
66
102
  end
67
103
 
68
104
  end
105
+
69
106
  end
107
+ end
70
108
 
71
109
  private
72
110
 
111
+ def creation_command(section)
112
+ "Adminpanel::Section.new(\n" +
113
+ ":name => \"#{section.name}\",\n" +
114
+ "\t:has_description => #{section.has_description},\n" +
115
+ "\t:description => \"#{section.description}\",\n" +
116
+ "\t:key => \"#{section.key}\",\n" +
117
+ "\t:page => \"#{section.page}\",\n" +
118
+ "\t:has_image => #{section.has_image}\n" +
119
+ ").save\n"
120
+
121
+ end
122
+
73
123
  def create_image_of(model_id)
74
124
  image_instance = Adminpanel::Image.new(
75
125
  :model => model.display_name,
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "adminpanel namespace task" do
3
+ describe "adminpanel rake task" do
4
4
 
5
5
  before :all do
6
6
  Rake.application.rake_require "tasks/adminpanel/adminpanel"
@@ -16,7 +16,7 @@ describe "adminpanel namespace task" do
16
16
 
17
17
 
18
18
  it "should generate 20 product records" do
19
- Adminpanel::Product.count.should eq 20
19
+ Adminpanel::Product.all.count.should eq 20
20
20
  end
21
21
 
22
22
  it "attributes shouldn't be nil" do
@@ -29,4 +29,20 @@ describe "adminpanel namespace task" do
29
29
  has_nil_attribute.should eq false
30
30
  end
31
31
  end
32
+
33
+ describe "adminpanel:section[about, mission]" do
34
+ before do
35
+ Rake.application.invoke_task "adminpanel:section[about, mission]"
36
+ end
37
+
38
+ it "should create a section with name 'mission' and section 'about'" do
39
+ (
40
+ (Adminpanel::Section.last.name.should eq("Mission")) &&
41
+ (Adminpanel::Section.last.page.should eq("about")) &&
42
+ (Adminpanel::Section.last.key.should eq("mission")) &&
43
+ (Adminpanel::Section.last.has_description.should be_true) &&
44
+ (Adminpanel::Section.last.has_image.should be_false)
45
+ )
46
+ end
47
+ end
32
48
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adminpanel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 1
10
- version: 1.2.1
9
+ - 2
10
+ version: 1.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jose Ramon Camacho
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2014-03-07 00:00:00 -06:00
19
+ date: 2014-03-10 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -446,13 +446,9 @@ files:
446
446
  - app/views/adminpanel/pages/index.html.erb
447
447
  - app/views/adminpanel/sections/_image_fields.html.erb
448
448
  - app/views/adminpanel/sections/_sections_table.html.erb
449
- - app/views/adminpanel/sections/create.html.erb
450
- - app/views/adminpanel/sections/destroy.html.erb
451
449
  - app/views/adminpanel/sections/edit.html.erb
452
450
  - app/views/adminpanel/sections/index.html.erb
453
- - app/views/adminpanel/sections/new.html.erb
454
451
  - app/views/adminpanel/sections/show.html.erb
455
- - app/views/adminpanel/sections/update.html.erb
456
452
  - app/views/adminpanel/sessions/new.html.erb
457
453
  - app/views/adminpanel/users/_user_form.html.erb
458
454
  - app/views/adminpanel/users/edit.html.erb
@@ -1,2 +0,0 @@
1
- <h1>Admin::Sections#create</h1>
2
- <p>Find me in app/views/admin/sections/create.html.erb</p>
@@ -1,2 +0,0 @@
1
- <h1>Admin::Sections#destroy</h1>
2
- <p>Find me in app/views/admin/sections/destroy.html.erb</p>
@@ -1,27 +0,0 @@
1
- <% provide(:page_title, "Nueva") %>
2
- <% breadcrumb_add('Secciones', sections_path) %>
3
- <div class="row-fluid">
4
- <div class = "widget widget-padding span12">
5
- <div class = "widget-header"><i class = "icon-tasks"></i><h5>Sección</h5></div>
6
- <div class = "widget-body">
7
- <div class = "widget-forms clearfix">
8
- <%= custom_form_for(@section, :url => sections_path) do |f| %>
9
- <%= render 'shared/error_messages', :object => @section %>
10
- <%= f.text_field :name, :label => "Nombre", :placeholder => "Nombre de la seccion" %>
11
- <%= f.text_field :key, :label => "Identificador", :placeholder => "Identificador" %>
12
- <div class="control-group">
13
- <label class="control-label">Descripción</label>
14
- <div class="controls">
15
- <%= f.cktext_area :description, :label => t("Description") %>
16
- </div>
17
- </div>
18
- <%= f.radio_button_group :has_image, ['1', '0'], :label => "Tiene Imagen" %>
19
- <%= f.radio_button_group :has_description, ['1', '0'], :label => "Tiene Descripcion" %>
20
- </div>
21
- </div>
22
- <div class = "widget-footer">
23
- <%= f.submit "Agregar", :disable_with => 'Submiting...' %>
24
- </div>
25
- <% end -%>
26
- </div>
27
- </div>
@@ -1,2 +0,0 @@
1
- <h1>Admin::Sections#update</h1>
2
- <p>Find me in app/views/admin/sections/update.html.erb</p>