Module: Zena::Use::Refactor::ViewMethods
- Includes:
- Common
- Defined in:
- lib/zena/use/refactor.rb
Overview
ControllerMethods
Instance Method Summary collapse
-
#add_place_holder(str) ⇒ Object
TODO: refactor with new RedCloth.
-
#css_edit(css_file = 'zen.css') ⇒ Object
TODO: remove ?.
-
#fsize(size) ⇒ Object
return a readable text version of a file size TODO: use number_to_human_size instead.
-
#replace_placeholders(str) ⇒ Object
Replace placeholders by their real values.
-
#rnd ⇒ Object
TODO: see if this is still needed.
-
#session ⇒ Object
We need to create the accessor for zafu calls to the helper to work when compiling templates.
-
#show(obj, sym, opt = {}) ⇒ Object
TODO: is this still used ?.
-
#traductions(opts = {}) ⇒ Object
Traductions as a list of links.
Methods included from Common
Instance Method Details
#add_place_holder(str) ⇒ Object
TODO: refactor with new RedCloth
45 46 47 48 49 50 |
# File 'lib/zena/use/refactor.rb', line 45 def add_place_holder(str) @placeholders ||= {} key = "[:::#{self.object_id}.#{@placeholders.keys.size}:::]" @placeholders[key] = str key end |
#css_edit(css_file = 'zen.css') ⇒ Object
TODO: remove ?
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/zena/use/refactor.rb', line 117 def css_edit(css_file = 'zen.css') return '' if RAILS_ENV == 'production' str = <<ENDTXT <div id='css_edit'> <div id='css' onclick='cssUpdate()'></div> <script type="text/javascript"> var c=0 var t function timedCount() { var file = $('css_file').value if (c == '#'){ c = '_' } else { c = '#' } document.getElementById('css_counter').innerHTML=c new Ajax.Request('/z/version/css_preview', {asynchronous:true, evalScripts:true, parameters:'css='+file}); t=setTimeout("timedCount()",2000) } function stopCount() { clearTimeout(t) } </script> <form> <input type="button" value="Start CSS" onclick="timedCount()"> <input type="button" value="Stop CSS" onclick="stopCount()"> <span id='css_counter'></span> <input type='text' id='css_file' name='css_file' value='#{css_file}'/> </form> </div> ENDTXT end |
#fsize(size) ⇒ Object
return a readable text version of a file size TODO: use number_to_human_size instead
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/zena/use/refactor.rb', line 62 def fsize(size) size = size.to_f if size >= 1024 * 1024 * 1024 sprintf("%.2f Gb", size/(1024*1024*1024)) elsif size >= 1024 * 1024 sprintf("%.1f Mb", size/(1024*1024)) elsif size >= 1024 sprintf("%i Kb", (size/(1024)).ceil) else sprintf("%i octets", size) end end |
#replace_placeholders(str) ⇒ Object
Replace placeholders by their real values
53 54 55 56 57 58 |
# File 'lib/zena/use/refactor.rb', line 53 def replace_placeholders(str) (@placeholders || {}).each do |k,v| str.gsub!(k,v) end str end |
#rnd ⇒ Object
TODO: see if this is still needed. Creates a pseudo random string to avoid browser side ajax caching
29 30 31 |
# File 'lib/zena/use/refactor.rb', line 29 def rnd Time.now.to_i end |
#session ⇒ Object
We need to create the accessor for zafu calls to the helper to work when compiling templates. Do not ask me why this works…
34 35 36 |
# File 'lib/zena/use/refactor.rb', line 34 def session @session || {} end |
#show(obj, sym, opt = {}) ⇒ Object
TODO: is this still used ?
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/zena/use/refactor.rb', line 76 def show(obj, sym, opt={}) return show_title(obj, opt) if sym == :title if opt[:as] key = "#{opt[:as]}#{obj.zip}.#{obj.version.number}" preview_for = opt[:as] opt.delete(:as) else key = "#{sym}#{obj.zip}.#{obj.version.number}" end if opt[:text] text = opt[:text] opt.delete(:text) else text = obj.send(sym) if text.blank? && sym == :summary text = obj.text opt[:images] = false else opt.delete(:limit) end end if [:text, :summary].include?(sym) if obj.kind_of?(TextDocument) && sym == :text lang = obj.content_lang lang = lang ? " lang='#{lang}'" : "" text = "<code#{lang} class='full'>#{text}</code>" end text = zazen(text, opt) klass = " class='zazen'" else klass = "" end if preview_for render_to_string :partial=>'nodes/show_attr', :locals=>{:id=>obj[:id], :text=>text, :preview_for=>preview_for, :key=>key, :klass=>klass, :key_on=>"#{key}#{Time.now.to_i}_on", :key_off=>"#{key}#{Time.now.to_i}_off"} else "<div id='#{key}'#{klass}>#{text}</div>" end end |
#traductions(opts = {}) ⇒ Object
Traductions as a list of links
156 157 158 159 160 161 162 163 |
# File 'lib/zena/use/refactor.rb', line 156 def traductions(opts={}) obj = opts[:node] || @node trad_list = [] (obj.traductions || []).each do |ed| trad_list << "<span#{ ed.lang == visitor.lang ? " class='current'" : ''}>" + link_to( _(ed[:lang]), zen_path(obj,:lang=>ed[:lang])) + "</span>" end trad_list end |