<% end %>
<%=
res = 'var hoboParts = {};'
# FIXME: This should interrogate the model-router - not the models
unless Hobo::Model.all_models.empty?
# Tell JS code how to pluralize names, unless they follow the simple rule
names = Hobo::Model.all_models.map do |m|
m = m.name.underscore
"#{m}: '#{m.pluralize}'" unless m.pluralize == m + 's'
end.compact
res << "var pluralisations = {#{names * ', '}}; "
end
base = [base_url, subsite].compact.join("/")
res << "urlBase = '#{base}'; hoboPagePath = '#{request.fullpath}'"
if protect_against_forgery?
res << "; formAuthToken = { name: '#{request_forgery_protection_token}', value: '#{form_authenticity_token}' }"
end
res
%><%=
if this.nil?
nil_view unless if_present
else
if this.is_a?(Array)
count
elsif this.is_a?(Class)
type_name(attributes)
elsif (name_attr = this.class.try.name_attribute) && can_view?(this, name_attr)
view(merge_attrs(attributes, {:field => name_attr}))
elsif can_view?(this)
h this.to_s
end
end
%><%=
type ||= (this if this.is_a?(Class)) || this.try.member_class || this.class
name = type.respond_to?(:model_name) ? type.model_name.human : type.name
name = dasherize ? name.underscore.dasherize : name.titleize
name = name.pluralize if plural
name = name.downcase if lowercase
name
%><%=
if (attr = this.try.origin_attribute)
name = attr.to_s
name = dasherize ? name.underscore.dasherize : name.titleize
name = name.singularize if singular
name = name.downcase if lowercase
name
else
type_name(:plural => !singular, :lowercase => lowercase, :dasherize => dasherize)
end
%><%=
content = parameters.default
params = self.query_params.merge(params || HashWithIndifferentAccess.new) if query_params
if href || attributes[:name]
# Regular link
href += "?" + params.map { |n, v| "#{n}=#{v}" }.join('&') if !params.blank?
element(:a, attributes.update(:href => href), content)
else
target = to || this
if target.nil?
Dryml.last_if = false
nil_view
elsif action == "new"
# Link to a new object form
new_record = target.new
new_record.set_creator(current_user)
href = object_url(target, "new", params._?.merge(:subsite => subsite))
if href && (force || can_create?(new_record))
new_class_name = if target.respond_to?(:proxy_reflection)
target.proxy_reflection.klass.name
else
target.name
end
add_classes!(attributes, "new-#{new_class_name.underscore}-link")
content = "New #{new_class_name.titleize}" if content.blank?
Dryml.last_if = true
element(:a, attributes.update(:href => href), content)
else
Dryml.last_if = false
""
end
else
# Link to an existing object
content = name if content.blank?
href = object_url(target, action, (params || {}).merge(:subsite => subsite))
if href.nil?
# This target is registered with Hobo::Routes as not linkable
content
else
css_class = target.try.origin_attribute || target.class.name.underscore.dasherize
add_classes!(attributes, "#{css_class}-link")
href.sub!(/\?|$/, ".#{format}\\0") unless format.blank?
# Set default link text if none given
element(:a, attributes.update(:href => href), content)
end
end
end
%><%=
raise Hobo::PermissionDeniedError, "view of non-viewable field '#{this_field}' of #{this_parent.typed_id rescue this_parent}" unless
can_view?
res = if this.nil? && if_blank.nil?
this_type.is_a?(Class) && this_type <= String ? "" : nil_view
elsif (refl = this_field_reflection) && refl.macro == :has_many
collection_view(attributes)
else
view_tag = find_polymorphic_tag("view")
if view_tag == "view" # i.e. it didn't find a type specific tag
if this.respond_to?(:to_html)
this.to_html(scope.xmldoctype)
else
this.to_s
end
else
attrs = add_classes(attributes, "view", type_and_field._?.dasherize, model_id_class)
view_attrs = attrs_for(view_tag)
the_view = send(view_tag, attrs & view_attrs)
the_view = if_blank if if_blank && the_view.blank?
truncate = 30 if truncate == true
the_view = self.truncate(the_view, :length => truncate.to_i) if truncate
the_view = the_view.strip
if no_wrapper
the_view
else
wrapper = if inline
:span
elsif block || this_type <= HoboFields::Types::Text
:div
else
:span
end
element(wrapper, attrs - view_attrs, the_view)
end
end
end
Dryml.last_if = !res.blank?
res
%><%= this.empty? ? "(none)" : context_map { a }.safe_join(", ") %><%= this && (format||= :default) && I18n.backend.localize(I18n.locale, this, format) %><%= this && (format||= :default) && I18n.backend.localize(I18n.locale, this, format) %><%= this && (format||= :default) && I18n.backend.localize(I18n.locale, this, format) %><%= format ? format % this : number_with_delimiter(this) %><%=
if !(this.class == String) && this.respond_to?(:to_html) # workaround for Maruku which adds String#to_html : (
this.to_html(scope.xmldoctype)
else
h(this).gsub("\n", " ")
end
%><%= this ? t('hobo.boolean_yes', :default => 'Yes') : t('hobo.boolean_no', :default => 'No') %><%=
raise Exception.new("asked for count of a string") if this.is_a?(String)
Rails.logger.warn('The "prefix" attribute is deprecated: please, use a locale string') unless prefix.blank?
c = this.try.to_int || this.try.total_entries || (this.try.loaded? && this.try.length) || this.try.count || this.try.length
# generated label will be pluralized
label ||= case
when this.is_a?(Class)
this.model_name.human(:count=>c)
when (attr = this.try.origin_attribute)
this_parent.class.human_attribute_name(attr, :count=>c)
else
this.member_class.model_name.human(:count=>c)
end
label = label.downcase if lowercase
Dryml.last_if = c > 0 if if_any
if if_any && c == 0
""
else
if summary.blank? # old behaviour
main = label.blank? ? c : "#{c} #{label}"
if prefix.in? %w(are is)
prefix = c == 1 ? "is" : "are"
end
(prefix ? "#{prefix} #{main}" : main.to_s)
else
key = summary.kind_of?(String) ? summary : "default"
default = c == 1 ? "There is 1 #{label}" : "There are #{c} #{label}"
t "tags.count.#{key}", {:count=>c, :label=>label, :default=>default}.merge(attributes)
end
end
%>
<% name ||= Hobo.current_theme -%>
<% Rails.logger.warn "'titleize' is a deprecated attribute of the 'you' tag. Please, use 'capitalize' instead." -%>
<% raise ArgumentError, "You can add only one attribute-key to the 'you' tag." if attributes.size > 1 -%>
<% k = case
when attributes[:have] then 'have'
when attributes[:are] then 'are'
when attributes[:do] then 'do'
end -%>
<%= s = t("tags.you.current_user.#{k || attributes.keys.first || 'default'}",:default=>"you #{k}")
(titleize||capitalize) ? s.sub(/^./){|c| c.upcase} : s %>
<%= s = t("tags.you.other_user.#{k || attributes.keys.first || 'default'}", :name=>this.name,
:default=>"#{this.name} #{'has' if attributes[:have]}#{'is' if attributes[:are]}#{'does' if attributes[:do]}")
(titleize||capitalize) ? s.sub(/^./){|c| c.upcase} : s %>
<%=
key ||= 'default'
# prepare symbolized attributes for merging
attrs = {}
attributes.each_pair{|k,v| attrs[k.to_sym] = v}
d = "#{your_default} #{all_parameters.default}"
options = {:default=>[d], :count=>(attrs[:count]||1), :name=>this.name}
your_key = key.split('.').last
unless key.eql?(your_key) || attrs.has_key?(your_key.to_sym)
options[your_key.to_sym] = t(key, :count=>options[:count], :default=>your_key.titleize)
end
s = if this == current_user
options[:default].unshift :"tags.your.default.current_user"
t("tags.your.#{your_key}.current_user", options.merge(attrs))
else
options[:default].unshift :"tags.your.default.other_user"
t("tags.your.#{your_key}.other_user", options.merge(attrs))
end
capitalize ? s.sub(/^./){|c| c.upcase} : s
%><%=
(word =~ /^[aeiou]/i ? "an " : "a ") + word
%><%=
(word =~ /^[aeiou]/i ? "An " : "A ") + word
%><%= this.join(join || ", ") %>