Module: WorldFlags::Helper::View

Defined in:
lib/world_flags/helper/view.rb,
lib/world_flags/helper/view/util.rb

Defined Under Namespace

Modules: Util

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.flag_sizesObject



6
7
8
# File 'lib/world_flags/helper/view.rb', line 6

def self.flag_sizes
  [16, 24, 32, 48, 64]
end

Instance Method Details

#flag(code, *args) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/world_flags/helper/view.rb', line 44

def flag code, *args
  options = args.extract_options!
  name = args.first.kind_of?(String) ? args.first : WorldFlags.label(code, options)        

  label = WorldFlags::Helper::View::Util.label_for options
  title = WorldFlags::Helper::View::Util.title_for name, options

   WorldFlags.flag_tag, label.html_safe, WorldFlags::Helper::View::Util.flag_options(code, title, name, options)
end

#flag_title(code, *args) ⇒ Object



54
55
56
57
58
59
# File 'lib/world_flags/helper/view.rb', line 54

def flag_title code, *args
  options = args.extract_options!
  name = args.first.kind_of?(String) ? args.first : WorldFlags.label(code, options)        

  flag code, name, options.merge(:title => true)
end

#flags(*args) ⇒ Object

should look up translation for each code



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/world_flags/helper/view.rb', line 24

def flags *args
  options = args.extract_options!
  args.flatten!
  args.inject("") do |res, elem|
    case elem
    when String, Symbol
      code = elem
      name = WorldFlags.label(code, options)
    else
      raise ArgumentError, "Bad argument: #{args}, must be Array"
    end       
    res << flag(code, name, options)
  end.html_safe
end

#flags_list(size = 24, options = {}, &block) ⇒ Object Also known as: flag_list



10
11
12
13
14
15
16
17
18
# File 'lib/world_flags/helper/view.rb', line 10

def flags_list size = 24, options = {}, &block
  raise "Missing block" unless block_given?
  unless WorldFlags::Helper::View.flag_sizes.include?(size.to_i)
    raise "Supported sizes are only #{WorldFlags::Helper::View.flag_sizes}" 
  end
  content = capture(&block)
  xclass = options[:class] ? " #{options[:class]}" : ''
   WorldFlags.flag_list_tag, content, :class => "f#{size} flags#{xclass}"
end

#flags_title(*args) ⇒ Object



39
40
41
42
# File 'lib/world_flags/helper/view.rb', line 39

def flags_title *args
  options = args.extract_options!
  flags args, options.merge(:title => true)
end

#use_flags(size = 24) ⇒ Object



61
62
63
# File 'lib/world_flags/helper/view.rb', line 61

def use_flags size = 24
  stylesheet_link_tag "flags/flags#{size}"
end