Module: Lindo
- Defined in:
- lib/lindo.rb,
lib/lindo/browser.rb
Defined Under Namespace
Classes: Browser
Constant Summary collapse
- TMP =
File.join(RAILS_ROOT, "tmp", "lindo")
- RESPONSE_TXT =
File.join(TMP, "response.txt")
- RESPONSE_HTML =
File.join(TMP, "response.html")
- ASSETS =
%w(images stylesheets javascripts)
Instance Method Summary collapse
- #copy_assets ⇒ Object
- #create_tmp_dir ⇒ Object
- #open_from_file(data, file) ⇒ Object
- #scrub(data) ⇒ Object
- #vr(format = :web) ⇒ Object
Instance Method Details
#copy_assets ⇒ Object
27 28 29 30 31 32 |
# File 'lib/lindo.rb', line 27 def copy_assets ASSETS.each do |e| dir = File.join(RAILS_ROOT, "public", e) FileUtils.cp_r(dir, TMP) if File.exists?(dir) end end |
#create_tmp_dir ⇒ Object
23 24 25 |
# File 'lib/lindo.rb', line 23 def create_tmp_dir FileUtils.mkdir_p(TMP) unless File.exists?(TMP) end |
#open_from_file(data, file) ⇒ Object
34 35 36 37 38 |
# File 'lib/lindo.rb', line 34 def open_from_file(data, file) scrub(data) File.open(file, File::CREAT|File::TRUNC|File::WRONLY) { |f| f << data } Browser.open(file) end |
#scrub(data) ⇒ Object
40 41 42 |
# File 'lib/lindo.rb', line 40 def scrub(data) ASSETS.each { |e| data.gsub!("=\"/#{e}/", "=\"#{e}/") } end |
#vr(format = :web) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lindo.rb', line 10 def vr(format=:web) create_tmp_dir copy_assets if format.is_a?(Symbol) case format when :web then open_from_file(@response.body, RESPONSE_HTML) when :html then open_from_file(@response.body, RESPONSE_TXT) end else open_from_file(format, RESPONSE_HTML) end end |