lib/sugar/actionview.rb in krasivotokak-sugar-0.0.23 vs lib/sugar/actionview.rb in krasivotokak-sugar-0.0.25
- old
+ new
@@ -9,20 +9,21 @@
action_name = controller.action_name
VIEW_PLACEHOLDERS[action_name] || action_name
end
def default_page_title
- case action_name
- when 'index'
- controller_name.camelize
- when 'new', 'create'
- t("#{t('new', :default => 'New')} #{controller_name.classify.constantize.human_name}")
- when 'edit', 'update'
- t("#{t('editing', :default => 'Editing')} #{controller_name.classify.constantize.human_name}")
- else
- t("#{controller_name}.#{view_name}.title")
- end
+ text = case action_name
+ when 'index'
+ controller_name.camelize
+ when 'new', 'create'
+ t("#{t('new', :default => 'New')} #{controller_name.classify.constantize.human_name}")
+ when 'edit', 'update'
+ t("#{t('editing', :default => 'Editing')} #{controller_name.classify.constantize.human_name}")
+ else
+ t("#{controller_name}.#{view_name}.title")
+ end
+ %(<span class="trasnlation_missing">#{text}</span>)
end
# Return page title for use in layout
def page_title(title = nil)
@page_title = if title
@@ -30,10 +31,15 @@
else
@page_title || t("#{controller_name}.#{view_name}.title", :default => default_page_title)
end
end
+ def html_page_title(default = false, separator = ' | ')
+ default ||= t('application.title')
+ [page_title, default].compat.join(separator)
+ end
+
# Put submit with proper text
def submit(form, title = nil)
title ||= t("#{controller.controller_name}.#{view_name}.submit",
:default => form.object.new_record? ? "#{t('add', :default => 'Add')} #{form.object.class.human_name}" : "#{t('save', :default => 'Save')} #{form.object.class.human_name}")
form.submit(title)
@@ -92,11 +98,11 @@
:class => 'ajax edit action')
end
def button_to_delete(something, title = nil)
title ||= t('.delete',
- :default => "Delete #{(something.is_a?(Array) ? something.last : something).class.human_name}")
+ :default => %(Delete #{(something.is_a?(Array) ? something.last : something).class.human_name}))
button_to(title,
polymorphic_path(something),
:class => 'delete action',
:method => :delete,
:confirm => t('sure', :default => 'Are you sure?'))
@@ -144,9 +150,24 @@
content << form.text_field(:"#{field}_max")
end
end
end
- end
+ def human(*args)
+ if args.size == 2
+ args.first.human_attribute_name(args.second.to_s)
+ else
+ args.first.human_name
+ end
+ end
+ def zebra
+ {:class => cycle('even', 'odd')}
+ end
+
+ def translatable(text, key = nil)
+ key ||= ".#{text.gsub(/[\s\.,-]+/, '_').downcase}"
+ translate(key, :default => text)
+ end
+ end
end