Permalink
Browse files

Release 0.2.1

  • Loading branch information...
1 parent d41affe commit 7aaaff9b2e0438fe602de12c372871b33d4154db @midas committed Apr 6, 2009
Showing with 40 additions and 4 deletions.
  1. +5 −0 History.txt
  2. +1 −0 Manifest.txt
  3. +3 −3 guilded.gemspec
  4. +2 −1 lib/guilded.rb
  5. +29 −0 lib/guilded/rails/inactive_record/human_attribute_hint.rb
View
@@ -1,3 +1,8 @@
+= 0.2.0 2009-04-06
+
+* Added human attribute hint support for InactiveRecord
+
+
= 0.2.0 2009-03-27
* Added Mark Perkins jquery-url plugin and made it a default library
View
@@ -12,6 +12,7 @@ lib/guilded/rails.rb
lib/guilded/rails/active_record/human_attribute_hint.rb
lib/guilded/rails/active_record/human_attribute_override.rb
lib/guilded/rails/helpers.rb
+lib/guilded/rails/inactive_record/human_attribute_hint.rb
lib/guilded/rails/view_helpers.rb
rails_generators/guilded_assets/guilded_assets_generator.rb
rails_generators/guilded_assets/templates/guilded.js
View
View
@@ -8,6 +8,7 @@
require 'guilded/rails/view_helpers'
require 'guilded/rails/active_record/human_attribute_hint'
require 'guilded/rails/active_record/human_attribute_override'
+require 'guilded/rails/inactive_record/human_attribute_hint'
# Guilded is a framework for creating reusable UI components for web applications. Guilded provides the facilities to
# easily add components and all of their required assets to a page.
@@ -71,7 +72,7 @@
# <%= g_load_alerter :skin => 'blueish', :id => 'load_alerter' %>
#
module Guilded
- VERSION = '0.2.0'
+ VERSION = '0.2.1'
end
ActionView::Base.send( :include, Guilded::Rails::ViewHelpers ) if defined?( ActionView )
@@ -0,0 +1,29 @@
+module InactiveRecord
+ class Base
+ class <<self
+ # Allows alternate humanized versions of attributes to be set. For example, an attribute such as 'num_employees' would be
+ # converted to 'Num employees' normally using <tt>human_attribute_name</tt>. More descriptive text can be set. Example:
+ # attr_human_name 'num_employees' => 'Number of employees'
+ def attr_human_hint(attributes) # :nodoc:
+ return unless table_exists?
+
+ attributes.stringify_keys!
+ write_inheritable_hash("attr_human_hint", attributes || {})
+
+ # assign the current class to each column that is being assigned a new human attribute name
+ self.columns.reject{|c| !attributes.has_key?(c.name)}.each{|c| c.parent_record_class = self}
+ end
+
+ # Returns a hash of alternate human name conversions set with <tt>attr_human_name</tt>.
+ def human_hint_attributes # :nodoc:
+ read_inheritable_attribute("attr_human_hint")
+ end
+
+ # Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
+ # Person.human_attribute_name("first_name") # => "First name"
+ def human_attribute_hint(attribute_key_name) #:nodoc:
+ (read_inheritable_attribute("attr_human_hint") || {})[attribute_key_name.to_s] || ''
+ end
+ end
+ end
+end

0 comments on commit 7aaaff9

Please sign in to comment.