wheels 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/application_controller.rb +1 -0
- data/app/controllers/users_controller.rb +4 -1
- data/app/helpers/application_helper.rb +52 -0
- data/app/models/access_control_entry.rb +5 -11
- data/app/models/profile.rb +1 -0
- data/app/models/user.rb +10 -4
- data/app/views/users/edit.html.haml +31 -14
- data/lib/wheels/active_record_extensions.rb +5 -35
- data/lib/wheels/html_writer.rb +49 -0
- data/lib/wheels/routes.rb +1 -1
- data/lib/wheels.rb +1 -0
- data/wheels.gemspec +3 -2
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.14
|
@@ -9,8 +9,11 @@ class UsersController < InheritedResources::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def update
|
12
|
+
resource
|
13
|
+
|
14
|
+
|
12
15
|
update! do |success, failure|
|
13
|
-
failure.html{redirect_to
|
16
|
+
failure.html{redirect_to my_account_path}
|
14
17
|
success.html{flash[:notice] = "Your password has been updated."; redirect_to root_url}
|
15
18
|
end
|
16
19
|
end
|
@@ -9,6 +9,58 @@ module ApplicationHelper
|
|
9
9
|
content_tag(:li, content_tag(:a, content_tag(:span, name, :class=>name.underscore), :href=>url), :class=>_class)
|
10
10
|
end
|
11
11
|
|
12
|
+
# def your_basic_form(object, *options)
|
13
|
+
# if object.methods.include? :form_fields then options = object.form_fields.merge(options)
|
14
|
+
# options[:submit] ||= ""
|
15
|
+
# concat(capture do
|
16
|
+
# content_tag('div',
|
17
|
+
# form_for(object, remote=>options[:remote]|| false) {|f|
|
18
|
+
# if object.errors.any?
|
19
|
+
# content_tag('div',
|
20
|
+
# content_tag('h2', "#{pluralize(resource.errors.count, "error")} prohibited this change:") +
|
21
|
+
# content_tag('ul',
|
22
|
+
# resource.errors.full_messages.map{|msg| content_tag('li', msg)}.join('\n')
|
23
|
+
# )
|
24
|
+
# , :id=>'errorExplanation' )
|
25
|
+
# end
|
26
|
+
# options.except(:remote).each do |key, value|
|
27
|
+
# form_field(key, value, f)
|
28
|
+
# end
|
29
|
+
# },
|
30
|
+
# :class=>'form')
|
31
|
+
# end)
|
32
|
+
# end
|
33
|
+
|
34
|
+
# def form_field(key, value, form_helper)
|
35
|
+
# capture do
|
36
|
+
# if value.is_a?(Hash) || (value.is_a? Symbol && value.to_s.ends_with('_attributes')) # This means it's a field group.
|
37
|
+
# content_tag('div',
|
38
|
+
# content_tag('div', key.to_s, :class=>'fieldGroupTitle') +
|
39
|
+
# value.is_a?(Hash) ?
|
40
|
+
# value.map{|t,u| form_field(t,u)}.join('\n') :
|
41
|
+
# basic_fields_for(key, value, form_helper),
|
42
|
+
# :class=>'fieldGroup')
|
43
|
+
# else
|
44
|
+
# content_tag('div',
|
45
|
+
# content_tag('div',
|
46
|
+
# form_helper.label(key),
|
47
|
+
# :class=>'fieldName') +
|
48
|
+
# content_tag('div',
|
49
|
+
# form_helper.send(value, key),
|
50
|
+
# :class=>'fieldValue'),
|
51
|
+
# :class=>'field')
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
|
56
|
+
# def basic_fields_for(key, value, form_helper)
|
57
|
+
# capture do
|
58
|
+
# form_helper.fields_for value.to_s.gsub(/_attributes/, '').to_sym{|f|
|
59
|
+
|
60
|
+
# }
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
|
12
64
|
def sidebar_content(&block)
|
13
65
|
@sidebar = true
|
14
66
|
content_for(:sidebar) do
|
@@ -89,17 +89,11 @@ class AccessControlEntry < ActiveRecord::Base
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def role=(role)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
if role.is_numeric?
|
98
|
-
self.role_id= role
|
99
|
-
else
|
100
|
-
self.role_id= Role.find_by_name(role).id
|
101
|
-
end
|
102
|
-
end
|
92
|
+
if role.kind_of? Role
|
93
|
+
self.role_id = role.id
|
94
|
+
else
|
95
|
+
role = role.to_s.camelize
|
96
|
+
self.role_id = (role.is_numeric? ? role : Role.find_by_name(role).id) unless role.empty?
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
data/app/models/profile.rb
CHANGED
data/app/models/user.rb
CHANGED
@@ -4,12 +4,15 @@ class User < ActiveRecord::Base
|
|
4
4
|
has_one :profile, :dependent => :destroy
|
5
5
|
has_many :galleries, :dependent => :destroy
|
6
6
|
has_many :access_control_entries, :dependent=>:destroy
|
7
|
+
before_create :create_profile
|
8
|
+
|
9
|
+
form_attributes( {"Edit your profile" => :profile_attributes},
|
10
|
+
{"Change your password" => [:old_password, :new_password, {"Re-type password"=>:password_confirmation}]})
|
7
11
|
|
8
12
|
accepts_nested_attributes_for :profile
|
9
13
|
|
10
14
|
def initialize(*args)
|
11
15
|
super(*args)
|
12
|
-
build_profile unless profile
|
13
16
|
end
|
14
17
|
|
15
18
|
def self.nobody
|
@@ -21,8 +24,10 @@ class User < ActiveRecord::Base
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def create_profile
|
24
|
-
|
25
|
-
|
27
|
+
unless self.profile
|
28
|
+
build_profile(:alias=>email)
|
29
|
+
profile.save
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
def role?(role)
|
@@ -63,7 +68,8 @@ class FullyValidatedUser < User
|
|
63
68
|
attr_accessor :old_password
|
64
69
|
validates :email, :presence => true, :email => true
|
65
70
|
validates :old_password, :presence=>true , :password=>true
|
66
|
-
validates :password, :
|
71
|
+
validates :password, :length=>{:minimum=>6}
|
67
72
|
validates :password_confirmation, :equal_to=>{:other=>:password}
|
73
|
+
validates :phone, :phone=>true
|
68
74
|
end
|
69
75
|
|
@@ -8,15 +8,39 @@
|
|
8
8
|
%ul
|
9
9
|
- resource.errors.full_messages.each do |msg|
|
10
10
|
%li= msg
|
11
|
+
|
12
|
+
.fieldGroup
|
13
|
+
.fieldGroupTitle Edit your personal info
|
14
|
+
= f.fields_for :profile do |pf|
|
15
|
+
.field
|
16
|
+
.fieldName= pf.label :first_name
|
17
|
+
.fieldValue= pf.text_field :first_name
|
18
|
+
.field
|
19
|
+
.fieldName= pf.label :last_name
|
20
|
+
.fieldValue= pf.text_field :last_name
|
21
|
+
.field
|
22
|
+
.fieldName= f.label :email
|
23
|
+
.fieldValue= f.text_field :email
|
24
|
+
.field
|
25
|
+
.fieldName= pf.label :phone
|
26
|
+
.fieldValue= pf.text_field :phone
|
27
|
+
.field
|
28
|
+
.fieldName= label_tag "Company / Organization"
|
29
|
+
.fieldValue= pf.text_field :company
|
30
|
+
.field
|
31
|
+
.fieldName= pf.label :position
|
32
|
+
.fieldValue= pf.text_field :position
|
33
|
+
.fieldGroup
|
34
|
+
.fieldGroupTitle Change your password
|
11
35
|
.field
|
12
|
-
.fieldName Old Password:
|
13
|
-
= f.password_field :old_password, :id=>"old_password"
|
36
|
+
.fieldName= label_tag "Old Password:"
|
37
|
+
.fieldValue= f.password_field :old_password, :id=>"old_password"
|
14
38
|
.field
|
15
|
-
.fieldName New Password:
|
16
|
-
= f.password_field :password, :id=>"password"
|
39
|
+
.fieldName= label_tag "New Password:"
|
40
|
+
.fieldValue= f.password_field :password, :id=>"password"
|
17
41
|
.field
|
18
|
-
.fieldName Confirm Password:
|
19
|
-
= f.password_field :password_confirmation
|
42
|
+
.fieldName= label_tag "Confirm Password:"
|
43
|
+
.fieldalue= f.password_field :password_confirmation
|
20
44
|
.submit= f.submit "Change Password"
|
21
45
|
|
22
46
|
:css
|
@@ -25,19 +49,12 @@
|
|
25
49
|
}
|
26
50
|
|
27
51
|
= content_for :head do
|
28
|
-
= javascript_include_tag
|
52
|
+
= javascript_include_tag %w(jquery.validate jquery-validate/extra-methods.js)
|
29
53
|
|
30
54
|
|
31
55
|
:javascript
|
32
56
|
var checkingPassword = true;
|
33
57
|
$(function(){
|
34
|
-
jQuery.validator.addMethod("verify_user", function(value, element, params) {
|
35
|
-
//alert($(element).attr('data-verify-user-path'));
|
36
|
-
return $.ajax({
|
37
|
-
async: false,
|
38
|
-
url: $(element).attr('data-verify-user-path')+ '?password='+value
|
39
|
-
}).responseText == "true";
|
40
|
-
}, "Password is incorrect.");
|
41
58
|
|
42
59
|
$('form').validate({onkeyup: function(element) {}});
|
43
60
|
$('#old_password').rules("add", {verify_user : true, alphanumeric: true})
|
@@ -1,44 +1,14 @@
|
|
1
1
|
module Wheels
|
2
2
|
module ActiveRecordExtensions
|
3
|
-
def
|
3
|
+
def form_attributes(attrib={}, options={})
|
4
|
+
@form_attributes = attrib
|
4
5
|
class_eval do
|
5
|
-
|
6
|
-
|
7
|
-
def save_commentable_tags
|
8
|
-
tagging_contexts.each do |context|
|
9
|
-
next unless tag_list_cache_set_on(context)
|
10
|
-
|
11
|
-
tag_list = tag_list_cache_on(context).uniq
|
12
|
-
|
13
|
-
# Do it normal like, but get the taggings, too.
|
14
|
-
|
15
|
-
|
16
|
-
# Find existing tags or create non-existing tags:
|
17
|
-
tag_list = ActsAsTaggableOn::Tag.find_or_create_all_with_like_by_name(tag_list)
|
18
|
-
|
19
|
-
current_tags = tags_on(context)
|
20
|
-
old_tags = current_tags - tag_list
|
21
|
-
new_tags = tag_list - current_tags
|
22
|
-
|
23
|
-
# Find taggings to remove:
|
24
|
-
old_taggings = taggings.where(:tagger_type => nil, :tagger_id => nil,
|
25
|
-
:context => context.to_s, :tag_id => old_tags).all
|
26
|
-
|
27
|
-
if old_taggings.present?
|
28
|
-
# Destroy old taggings:
|
29
|
-
ActsAsTaggableOn::Tagging.destroy_all :id => old_taggings.map(&:id)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Create new taggings:
|
33
|
-
new_tags.each do |tag|
|
34
|
-
taggings.create!(:tag_id => tag.id, :context => context.to_s, :taggable => self)
|
35
|
-
end
|
36
|
-
end
|
6
|
+
def form_fields
|
7
|
+
self.class.instance_variable_get('@form_attributes')
|
37
8
|
end
|
38
|
-
after_save :save_commentable_tags
|
39
|
-
|
40
9
|
end
|
41
10
|
end
|
42
11
|
end
|
43
12
|
end
|
13
|
+
ActiveRecord::Base.extend Wheels::ActiveRecordExtensions
|
44
14
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
3
|
+
class HtmlWriter
|
4
|
+
include ActionView::Helpers::TagHelper
|
5
|
+
|
6
|
+
def initialize(representation={})
|
7
|
+
@representation = representation
|
8
|
+
end
|
9
|
+
|
10
|
+
# Wanna be able to do:
|
11
|
+
# HtmlWriter.new.div.div(:id=>:nice, :cool=>:bar).a('Cool', :href=>'http://...')
|
12
|
+
HtmlWriter.new.div[:fieldName].div.id('nice') {|h|
|
13
|
+
h.div(@page.comments) {|ht, comment|
|
14
|
+
ht.div
|
15
|
+
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
def method_missing(sym, *args, &block)
|
20
|
+
if args[0].is_a? Array
|
21
|
+
# Then the first argument is an array of objects.
|
22
|
+
end
|
23
|
+
@representation[sym] = {:args=>args[0]}
|
24
|
+
if block_given?
|
25
|
+
block.call(self)
|
26
|
+
end
|
27
|
+
return HtmlWriter.new(@representation[sym])
|
28
|
+
end
|
29
|
+
|
30
|
+
def val(value)
|
31
|
+
@representation[:value] = value
|
32
|
+
return self
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](html_class)
|
36
|
+
@representation[:args][:class] = html_class.to_s
|
37
|
+
return self
|
38
|
+
end
|
39
|
+
|
40
|
+
def id(_id)
|
41
|
+
@representation[:args][:class] = _id.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def html
|
45
|
+
concat
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/lib/wheels/routes.rb
CHANGED
@@ -49,7 +49,7 @@ module ActionDispatch::Routing
|
|
49
49
|
|
50
50
|
match '/css' => 'app_configs#css'
|
51
51
|
match '/admin' => "sitemaps#index"
|
52
|
-
match "
|
52
|
+
match "my_account" => "users#edit"
|
53
53
|
match "verify_password" => "users#verify", :format=>:json
|
54
54
|
end
|
55
55
|
end
|
data/lib/wheels.rb
CHANGED
@@ -2,6 +2,7 @@ require 'wheels/wheels_engine.rb'
|
|
2
2
|
require 'wheels/routes.rb'
|
3
3
|
require 'wheels/action_controller_extensions.rb'
|
4
4
|
require 'wheels/action_view_helper_extensions.rb'
|
5
|
+
require 'wheels/active_record_extensions.rb'
|
5
6
|
require 'wheels/flash_session_cookie_middleware.rb'
|
6
7
|
require 'wheels/paperclip_interpolations.rb'
|
7
8
|
require 'wheels/password_validators.rb'
|
data/wheels.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wheels}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.14"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tyler Gannon"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-16}
|
13
13
|
s.description = %q{Call rails generate wheels.}
|
14
14
|
s.email = %q{tgannon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -291,6 +291,7 @@ Gem::Specification.new do |s|
|
|
291
291
|
"lib/wheels/active_record_extensions.rb",
|
292
292
|
"lib/wheels/active_record_user_extensions.rb",
|
293
293
|
"lib/wheels/flash_session_cookie_middleware.rb",
|
294
|
+
"lib/wheels/html_writer.rb",
|
294
295
|
"lib/wheels/paperclip_interpolations.rb",
|
295
296
|
"lib/wheels/password_validators.rb",
|
296
297
|
"lib/wheels/routes.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 14
|
9
|
+
version: 0.1.14
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tyler Gannon
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-16 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -314,6 +314,7 @@ files:
|
|
314
314
|
- lib/wheels/active_record_extensions.rb
|
315
315
|
- lib/wheels/active_record_user_extensions.rb
|
316
316
|
- lib/wheels/flash_session_cookie_middleware.rb
|
317
|
+
- lib/wheels/html_writer.rb
|
317
318
|
- lib/wheels/paperclip_interpolations.rb
|
318
319
|
- lib/wheels/password_validators.rb
|
319
320
|
- lib/wheels/routes.rb
|