Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 59 lines (52 sloc) 2.529 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
# Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
# Copyright:: Copyright (c) 2012 Maurizio Casimirri
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Mcasimir
  module BasicViewsHelpers

      def meta(*args)
        default = {:charset => "utf-8", :x_ua_compatible => "IE=edge,chrome=1"}
        opts = default.merge(args.extract_options!)
        html = <<-HTML
<meta charset="#{opts[:charset]}" />
<meta http-equiv="X-UA-Compatible" content="#{opts[:x_ua_compatible]}"/>
<title>#{opts[:title]}</title>
<meta name="description" content="#{opts[:description]}"/>
HTML
        html.html_safe
      end
  
      def name_method_for(resource, opts = {})
        klass = resource.is_a?(Class) ? resource : resource.class
        any_names = ((klass.respond_to?(:column_names) ? klass.column_names : []) + klass.public_instance_methods).map {|name| "#{name}"}.uniq.delete_if {|meth| meth =~ /^_/}
        %w(title name label to_label key claim to_s).find {|meth| any_names.include?(meth)}
      end
      alias :title_method_for :name_method_for
      alias :label_method_for :name_method_for

      def name_for(resource, opts = {})
        resource.send(label_method_for(resource, opts))
      end
      alias :title_for :name_for
      alias :label_for :name_for

      def partial?(name)
        lookup_context.exists?(name, lookup_context.prefixes, true)
      end
  
  end
end

ActionView::Base.send :include, Mcasimir::BasicViewsHelpers
Something went wrong with that request. Please try again.