Module: Wakari::Translation::Model::ClassMethods

Defined in:
lib/wakari/models/translation/model.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_translation_class(content_class, association_name, meta_class, full_association_name, options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/wakari/models/translation/model.rb', line 39

def acts_as_translation_class(content_class, association_name, meta_class, full_association_name, options)
 has_locale! *Array.wrap(options[:locales])#, :accessible => false

 belongs_to :content, :class_name => "::Object::#{content_class.name}", :inverse_of => association_name, :counter_cache => :"#{association_name}_count"
 belongs_to :meta, :class_name => "::Object::#{meta_class.name}", :inverse_of => full_association_name, :counter_cache => :wakari_used

 self._meta_attributes =
 if meta_class < Wakari::Meta::Text || meta_class < Wakari::Meta::String
   [:value]
 else
   Array.wrap(options[:attributes]).map {|a| a.to_sym}
 end

 attr_accessible *_meta_attributes, :content_id, :meta_id, :_destroy, :position
 delegate *_meta_attributes, :to_s, :to => "(@_template_meta||meta)"
 delegate *_meta_attributes.collect {|attribute| "#{attribute}="}, :to => :template_meta
 
 (class << self; self; end).instance_eval do
   define_method :i18n_inherited_namespaced_scope do |resource| #:nodoc:
     :"#{content_class.i18n_namespaced_scope(resource)}.#{model_name.element}"
   end

   define_method :i18n_inherited_default_scope do |resource| #:nodoc:
     :"#{content_class.i18n_default_scope(resource)}.#{model_name.element}"
   end
 end

 define_method :stack do
   content.send(association_name)
 end
 
end

#dom_classObject



35
36
37
# File 'lib/wakari/models/translation/model.rb', line 35

def dom_class
  model_name.element
end

#human_attribute_name(attribute, options = {}) ⇒ Object



79
80
81
# File 'lib/wakari/models/translation/model.rb', line 79

def human_attribute_name(attribute, options = {})
  try_human_attribute_name(attribute, options)
end

#try_human_attribute_name(attribute, options = {}) ⇒ Object



72
73
74
75
76
77
# File 'lib/wakari/models/translation/model.rb', line 72

def try_human_attribute_name(attribute, options = {})
  super(attribute, options) do |defaults|
    defaults << :"#{i18n_inherited_namespaced_scope(:attributes)}.#{attribute}" ## added
    defaults << :"#{i18n_inherited_default_scope(:attributes)}.#{attribute}" ## added
  end
end