Methods
Public Instance methods
Set the meta description of the page Usefull for google & c.
[ show source ]
# File lib/view/helpers/frontend_helper.rb, line 14
14: def description(text)
15: content_for(:description) { text }
16: end
Override the default image tag with a special option resize that crop/resize on the fly the image and store them in uploads/thumb directory.
[ show source ]
# File lib/view/helpers/frontend_helper.rb, line 28
28: def image_tag(source, options = {})
29: options.symbolize_keys!
30: # We set here the upload path
31: upload_path = "uploads/thumbs"
32: # Now we can create a thumb on the fly
33: if options[:resize]
34: begin
35: geometry = options.delete(:resize)
36: filename = File.basename(source)
37: new_filename = "#{geometry}_#{filename}".downcase.gsub(/#/, '')
38: # Checking if we have just process them (we don't want to do the same job two times)
39: if File.exist?("#{Rails.root}/public/#{upload_path}/#{new_filename}")
40: options[:src] = "/#{upload_path}/#{new_filename}"
41: else # We need to create the thumb
42: FileUtils.mkdir("#{Rails.root}/tmp") unless File.exist?("#{Rails.root}/tmp")
43: # We create a temp file of the original file
44: # Notice that we can download them from an url! So this Image can reside anywhere on the web
45: if source =~ /#{URI.regexp}/
46: tmp = File.new("#{Rails.root}/tmp/#{filename}", "w")
47: tmp.write open(source).read
48: tmp.close
49: else # If the image is local
50: tmp = File.open(File.join("#{Rails.root}/public", path_to_image(source).gsub(/\?+\d*/, "")))
51: end
52: # Now we generate a thumb with our Thumbnail Processor (based on Paperclip)
53: thumb = Lipsiadmin::Attachment::Thumbnail.new(tmp, :geometry => geometry).make
54: # We check if our dir exists
55: FileUtils.mkdir_p("#{Rails.root}/public/#{upload_path}") unless File.exist?("#{Rails.root}/public/#{upload_path}")
56: # Now we put the image in our public path
57: File.open("#{Rails.root}/public/#{upload_path}/#{new_filename}", "w") do |f|
58: f.write thumb.read
59: end
60: # Finally we return the new image path
61: options[:src] = "/#{upload_path}/#{new_filename}"
62: end
63: rescue Exception => e
64: options[:src] = path_to_image(source)
65: ensure
66: File.delete(tmp.path) if tmp && tmp.path =~ /#{Rails.root}\/tmp/
67: File.delete(thumb.path) if thumb
68: end
69: end
70:
71: if size = options.delete(:size)
72: options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
73: end
74:
75: options[:src] ||= path_to_image(source)
76: options[:alt] ||= File.basename(options[:src], '.*').
77: split('.').first.to_s.capitalize
78:
79: if mouseover = options.delete(:mouseover)
80: options[:onmouseover] = "this.src='#{image_path(mouseover)}'"
81: options[:onmouseout] = "this.src='#{image_path(options[:src])}'"
82: end
83:
84: tag("img", options)
85: end
Set the meta keywords of the page Usefull for google & c.
[ show source ]
# File lib/view/helpers/frontend_helper.rb, line 20
20: def keywords(text)
21: content_for(:keywords) { text }
22: end
Set the title of the page and append at the end the name of the project Usefull for google & c.
[ show source ]
# File lib/view/helpers/frontend_helper.rb, line 8
8: def title(text)
9: content_for(:title) { text + " - #{AppConfig.project}" }
10: end