OSDN Git Service

t#31957:helperize
[pettanr/pettanr.git] / app / helpers / application_helper.rb
1 module ApplicationHelper
2   def full_url filename
3     request.protocol + request.host_with_port + filename
4   end
5   
6   def t_m(label)
7     l = label.split('.')
8     if l.size > 2
9       label
10     else
11       if l.size == 1
12         label.constantize.model_name.human
13       else
14         l.first.constantize.human_attribute_name(l.last)
15       end
16     end
17   end
18   
19   def t_select_items(items)
20     items.map {|i| [t(i[0]), i[1]] }
21   end
22   
23   def t_selected_item(name, index)
24     t(MagicNumber[name][index][0])
25   end
26   
27   def icon_tag name, opt = {}
28     title = opt[:object] ? (name.to_s + ' ID:' + opt[:object].id.to_s) : name
29     size = opt[:size] ? opt[:size].to_i : 35
30     tag :img, :src => asset_path(name.to_s.downcase + '.gif'), :width => size, :height => size, :alt => name.to_s + ' Icon', :title => title
31   end
32   
33   def author_icon opt = {}
34     icon_tag :Author, opt
35   end
36   
37   def artist_icon opt = {}
38     icon_tag :Artist, opt
39   end
40   
41   def comic_icon opt = {}
42     icon_tag :Comic, opt
43   end
44   
45   def story_icon opt = {}
46     icon_tag :Story, opt
47   end
48   
49   def panel_icon opt = {}
50     icon_tag :Panel, opt
51   end
52   
53   def panel_editor_javascript_include_tags
54     WritingFormat.list().map {|wf|
55 #      javascript_include_tag wf.engine_name
56       javascript_include_tag wf.engine_name + "/application"
57     }.join("\n") + 
58     SpeechBalloonTemplate.enable_list().map {|sbt|
59       stylesheet_link_tag sbt.engine_name + "/application"
60     }.join("\n") + 
61     SpeechBalloonTemplate.enable_list().map {|sbt|
62       javascript_include_tag sbt.engine_name + "/application"
63     }.join("\n")
64   end
65   
66 end