letter_opener_web 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,21 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
1
  //= require jquery-1.8.3.min
14
2
  //= require_tree .
15
3
 
16
4
  jQuery(function($) {
17
- $('.letter-opener tr').click(function() {
5
+ $('.letter-opener').on('click', 'tr', function() {
18
6
  var $this = $(this);
19
7
  $('iframe').attr('src', $this.find('a').attr('href'));
20
8
  $this.parent().find('.active').removeClass('active');
21
9
  $this.addClass('active');
22
10
  });
11
+
12
+ $('.refresh').click(function(e) {
13
+ e.preventDefault();
14
+
15
+ var table = $('.letter-opener');
16
+ table.find('tbody').empty().append('<tr><td colspan="2">Loading...</td></tr>');
17
+ table.load(table.data('letters-path') + ' .letter-opener', function() {
18
+ $('iframe').attr('src', $('.letter-opener tbody a:first-child()').attr('href'));
19
+ });
20
+ });
23
21
  });
@@ -41,7 +41,21 @@ module LetterOpenerWeb
41
41
  private
42
42
 
43
43
  def read_file(style)
44
- File.read("#{letters_location}/#{id}/#{style}.html")
44
+ contents = File.read("#{letters_location}/#{id}/#{style}.html")
45
+
46
+ # We cannot feed the whole file to an XML parser as some mails are
47
+ # "complete" (as in they have the whole <html> structure) and letter_opener
48
+ # prepends some information about the mail being sent, making REXML
49
+ # complain about it
50
+ contents.scan(/<a[^>]+>.+<\/a>/).each do |link|
51
+ xml = REXML::Document.new(link).root
52
+ unless xml.attributes['href'] =~ /(plain|rich).html/
53
+ xml.attributes['target'] = '_blank'
54
+ contents.gsub!(link, xml.to_s)
55
+ end
56
+ end
57
+
58
+ contents
45
59
  end
46
60
  end
47
61
  end
@@ -3,12 +3,18 @@
3
3
  <div class="span5">
4
4
  <h1>
5
5
  Letters
6
- <%= link_to clear_letters_path, method: 'delete', confirm: 'Are you sure?', class: 'btn btn-danger pull-right' do %>
7
- <i class="icon-trash icon-white"></i>
8
- Clear
9
- <% end %>
6
+ <span class="pull-right">
7
+ <%= link_to letters_path, class: 'btn refresh' do %>
8
+ <i class="icon-refresh"></i>
9
+ Refresh
10
+ <% end %>
11
+ <%= link_to clear_letters_path, method: 'delete', confirm: 'Are you sure?', class: 'btn btn-danger' do %>
12
+ <i class="icon-trash icon-white"></i>
13
+ Clear
14
+ <% end %>
15
+ </span>
10
16
  </h1>
11
- <table class="table table-hover letter-opener">
17
+ <table class="table table-hover letter-opener" data-letters-path="<%= letters_path %>">
12
18
  <thead>
13
19
  <tr>
14
20
  <th>ID</th>
@@ -1,3 +1,3 @@
1
1
  module LetterOpenerWeb
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "letter_opener_web/engine"
2
+ require 'rexml/document'
2
3
 
3
4
  module LetterOpenerWeb
4
5
  end
@@ -11,6 +11,7 @@ describe LetterOpenerWeb::LettersController do
11
11
 
12
12
  describe 'GET show' do
13
13
  let(:id) { 'an-id' }
14
+ # TODO: Move these to fixture files
14
15
  let(:rich_text) { "rich text href=\"plain.html\"" }
15
16
  let(:plain_text) { "plain text href=\"rich.html\"" }
16
17
  let(:letter) { mock(:letter, rich_text: rich_text, plain_text: plain_text, id: id) }
@@ -10,7 +10,7 @@ describe LetterOpenerWeb::Letter do
10
10
  ['1111_1111', '2222_2222'].each do |folder|
11
11
  FileUtils.mkdir_p("#{location}/#{folder}")
12
12
  File.open("#{location}/#{folder}/plain.html", 'w') {|f| f.write("Plain text for #{folder}") }
13
- File.open("#{location}/#{folder}/rich.html", 'w') {|f| f.write("Rich text for #{folder}") }
13
+ File.open("#{location}/#{folder}/rich.html", 'w') {|f| f.write("Rich text for #{folder} <!DOCTYPE html><a href='a-link.html'><img src='an-image.jpg'/>Link text</a>") }
14
14
  FileUtils.mkdir_p("#{Rails.root.join('tmp', 'letter_opener')}/#{folder}")
15
15
  File.open("#{Rails.root.join('tmp', 'letter_opener')}/#{folder}/rich.html", 'w') {|f| f.write("Rich text for #{folder}") }
16
16
  end
@@ -20,12 +20,22 @@ describe LetterOpenerWeb::Letter do
20
20
  FileUtils.rm_rf(location)
21
21
  end
22
22
 
23
- it 'loads rich version' do
24
- described_class.new(id: '1111_1111').rich_text.should == 'Rich text for 1111_1111'
23
+ describe 'rich text version' do
24
+ let(:id) { '1111_1111' }
25
+ subject { described_class.new(id: id).rich_text }
26
+
27
+ it { should =~ /Rich text for 1111_1111/ }
28
+
29
+ it 'changes links to show up on a new window' do
30
+ subject.should include("<a href='a-link.html' target='_blank'><img src='an-image.jpg'/>Link text</a>")
31
+ end
25
32
  end
26
33
 
27
- it 'loads plain text version' do
28
- described_class.new(id: '2222_2222').plain_text.should == 'Plain text for 2222_2222'
34
+ describe 'plain text version' do
35
+ let(:id) { '2222_2222' }
36
+ subject { described_class.new(id: id).plain_text }
37
+
38
+ it { should =~ /Plain text for 2222_2222/ }
29
39
  end
30
40
 
31
41
  describe '.search' do
@@ -0,0 +1,3 @@
1
+ tmp/
2
+ log/
3
+ Gemfile.lock
data/test-app/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source :rubygems
2
+
3
+ # Required by active_support
4
+ gem "tzinfo"
5
+
6
+ gem "tiny-rails"
7
+ gem "actionpack", "~> 3.2"
8
+ gem "actionmailer", "~> 3.2"
9
+ gem "railties", "~> 3.2"
10
+
11
+ gem "letter_opener_web", path: '../'
data/test-app/boot.rb ADDED
@@ -0,0 +1,42 @@
1
+ $:.unshift Dir.pwd
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default
5
+
6
+ require "tiny-rails"
7
+ require "rails"
8
+
9
+ require "action_controller/railtie"
10
+ require "sprockets/railtie"
11
+ require "action_mailer/railtie"
12
+
13
+ Bundler.require :default
14
+
15
+ class TinyRailsApp < Rails::Application
16
+ config.consider_all_requests_local = true
17
+
18
+ config.active_support.deprecation = :log
19
+
20
+ config.autoload_paths << config.root
21
+
22
+ config.middleware.delete "Rack::Lock"
23
+ config.middleware.delete "ActionDispatch::Flash"
24
+ config.middleware.delete "ActionDispatch::BestStandardsSupport"
25
+ config.middleware.use Rails::Rack::LogTailer, "log/#{Rails.env}.log"
26
+
27
+ # We need a secret token for session, cookies, etc.
28
+ config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
29
+
30
+ # Enable asset pipeline
31
+ config.assets.enabled = true
32
+ config.assets.debug = true
33
+ end
34
+
35
+ require 'initializers' if File.exists?('initializers.rb')
36
+
37
+ TinyRailsApp.initialize!
38
+
39
+ TinyRailsApp.routes.draw do
40
+ mount LetterOpenerWeb::Engine, at: "/"
41
+ match "/favicon.ico", :to => proc {|env| [200, {}, [""]] }
42
+ end
@@ -0,0 +1,2 @@
1
+ require './boot'
2
+ run TinyRailsApp
data/test-app/server ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require './boot'
4
+
5
+ options = {
6
+ :environment => nil,
7
+ :pid => nil,
8
+ :Port => 3000,
9
+ :Host => "0.0.0.0",
10
+ :AccessLog => [],
11
+ :app => TinyRailsApp,
12
+
13
+ # TODO:
14
+ # :server => 'thin'
15
+ }
16
+
17
+ Rack::Server.start options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letter_opener_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-06 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -113,7 +113,6 @@ files:
113
113
  - app/models/letter_opener_web/letter.rb
114
114
  - app/views/layouts/letter_opener_web/application.html.erb
115
115
  - app/views/letter_opener_web/letters/index.html.erb
116
- - config.ru
117
116
  - config/routes.rb
118
117
  - letter_opener_web.gemspec
119
118
  - lib/letter_opener_web.rb
@@ -129,6 +128,11 @@ files:
129
128
  - spec/internal/public/favicon.ico
130
129
  - spec/models/letter_opener_web/letter_spec.rb
131
130
  - spec/spec_helper.rb
131
+ - test-app/.gitignore
132
+ - test-app/Gemfile
133
+ - test-app/boot.rb
134
+ - test-app/config.ru
135
+ - test-app/server
132
136
  - vendor/assets/images/glyphicons-halflings-white.png
133
137
  - vendor/assets/images/glyphicons-halflings.png
134
138
  - vendor/assets/javascripts/bootstrap.min.js
@@ -147,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
151
  version: '0'
148
152
  segments:
149
153
  - 0
150
- hash: 3518792770742069574
154
+ hash: 2512558198014940067
151
155
  none: false
152
156
  required_rubygems_version: !ruby/object:Gem::Requirement
153
157
  requirements:
@@ -156,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
160
  version: '0'
157
161
  segments:
158
162
  - 0
159
- hash: 3518792770742069574
163
+ hash: 2512558198014940067
160
164
  none: false
161
165
  requirements: []
162
166
  rubyforge_project:
data/config.ru DELETED
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- require 'combustion'
5
- Bundler.require :default, :development
6
-
7
- Combustion.initialize! :action_controller, :action_view, :sprockets, :action_mailer
8
-
9
- run Combustion::Application