letter_opener_web 1.3.2 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +3 -4
  4. data/.travis.yml +4 -5
  5. data/CHANGELOG.md +21 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +6 -6
  9. data/app/controllers/letter_opener_web/letters_controller.rb +8 -2
  10. data/app/models/letter_opener_web/letter.rb +15 -4
  11. data/app/views/layouts/letter_opener_web/_javascripts.html.erb +564 -0
  12. data/app/views/layouts/letter_opener_web/_styles.html.erb +63 -0
  13. data/app/views/layouts/letter_opener_web/letters.html.erb +4 -3
  14. data/config/routes.rb +4 -4
  15. data/letter_opener_web.gemspec +12 -11
  16. data/lib/letter_opener_web/delivery_method.rb +6 -1
  17. data/lib/letter_opener_web/engine.rb +0 -10
  18. data/lib/letter_opener_web/version.rb +1 -1
  19. data/spec/controllers/letter_opener_web/letters_controller_spec.rb +19 -8
  20. data/spec/models/letter_opener_web/letter_spec.rb +14 -3
  21. data/spec/rails_helper.rb +1 -1
  22. data/spec/spec_helper.rb +8 -0
  23. metadata +12 -20
  24. data/app/assets/javascripts/letter_opener_web/application.js +0 -30
  25. data/app/assets/stylesheets/letter_opener_web/application.css.erb +0 -54
  26. data/bin/rails +0 -11
  27. data/vendor/assets/images/letter_opener_web/blue-dot.ico +0 -0
  28. data/vendor/assets/images/letter_opener_web/glyphicons-halflings-white.png +0 -0
  29. data/vendor/assets/images/letter_opener_web/glyphicons-halflings.png +0 -0
  30. data/vendor/assets/javascripts/letter_opener_web/bootstrap.min.js +0 -6
  31. data/vendor/assets/javascripts/letter_opener_web/favcount.js +0 -102
  32. data/vendor/assets/javascripts/letter_opener_web/jquery-1.8.3.min.js +0 -2
  33. data/vendor/assets/javascripts/letter_opener_web/jquery_ujs.js +0 -429
  34. data/vendor/assets/stylesheets/letter_opener_web/bootstrap.min.css +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a52b402271aaa9c2010cfd193fd3858e186328f0c13b4fafb3f449ed768eb62
4
- data.tar.gz: ad574fc2698517185a7b43a3dc02a431a12edf895f6bceb7b012d0cf61923f3b
3
+ metadata.gz: cf8f22bcc360d6d8da5a1e462a24faa5d8dfe4589a7cad91bebe688a06a1001c
4
+ data.tar.gz: f9cc899aee871f4d68ec12390be6470d62fba0b85123ecb38ae5a11e98899f42
5
5
  SHA512:
6
- metadata.gz: a1c1eccaa4ac748e90f57069697724a9d5b9f4482f29c5e5cf1766407dc32ac85161fca9f9cce89db063b73b84b9f7ece72538eb6a78adf6f34bc02ab250a52d
7
- data.tar.gz: 272edf9e6edf6912074367770a454dcc824ab1cec0eabba3b464b83eb319f744dbd6e42d0b77d5c4ef1ccc812c6df692ce8bb95d45f53b65d9e70469fb1bacb5
6
+ metadata.gz: 79ecd487c5042e2acfd3627a38ee8379e8a372c06a64aaa8c01be30cddf01b123dc23ec80dafe1cc94f7924698ef80304066c1b06a5d776f8304a547ddaa11be
7
+ data.tar.gz: c5fb0b7be26b025400c346a8d4850e834e890f578cfd6a849fd949d1b12c93999aaefef65c1e641e8a6fca2a25e866467f6f223527ed84cea94fb4022b07984e
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .ruby-version
5
6
  .yardoc
6
7
  InstalledFiles
7
8
  _yardoc
data/.rubocop.yml CHANGED
@@ -1,13 +1,12 @@
1
1
  ---
2
2
  AllCops:
3
- TargetRubyVersion: 2.3
3
+ TargetRubyVersion: 2.5
4
4
  Exclude:
5
5
  - "spec/dummy/bin/**/*"
6
6
  - "tmp/**/*"
7
7
  - "vendor/**/*"
8
8
 
9
- # not available in older versions of Ruby
10
- Layout/IndentHeredoc:
9
+ Layout/HeredocIndentation:
11
10
  Enabled: false
12
11
 
13
12
  Style/Documentation:
@@ -23,5 +22,5 @@ Metrics/BlockLength:
23
22
  Exclude:
24
23
  - spec/**/*_spec.rb
25
24
 
26
- Metrics/LineLength:
25
+ Layout/LineLength:
27
26
  Max: 120
data/.travis.yml CHANGED
@@ -1,15 +1,14 @@
1
- sudo: false
2
1
  language: ruby
3
2
 
4
3
  rvm:
5
- - 2.3.3
6
- - 2.2.6
7
- - 2.1.10
4
+ - "2.7"
5
+ - "2.6"
6
+ - "2.5"
8
7
 
9
8
  cache: bundler
10
9
 
11
10
  before_install:
12
- - gem update --system
11
+ - gem install bundler -v '< 2'
13
12
 
14
13
  notifications:
15
14
  email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [1.4.1](https://github.com/fgrehm/letter_opener_web/compare/v1.4.0...v1.4.1) (Oct 5, 2021)
2
+
3
+ - Ensure letter is within letters base path [#110](https://github.com/fgrehm/letter_opener_web/pull/110)
4
+
5
+ ## [1.4.0](https://github.com/fgrehm/letter_opener_web/compare/v1.3.4...v1.4.0) (Jan 29, 2020)
6
+
7
+ - Removed the dependency on the asset pipeline. Good news for API-only apps! [#83](https://github.com/fgrehm/letter_opener_web/pull/83)
8
+ - Avoid `require_dependency` if Zeitwerk is enabled [#98](https://github.com/fgrehm/letter_opener_web/pull/98)
9
+ - Drop support for old rubies and rails. Ruby 2.5+ is supported and Rails 4 is no longer tested [#100](https://github.com/fgrehm/letter_opener_web/pull/100)
10
+
11
+ ## [1.3.4](https://github.com/fgrehm/letter_opener_web/compare/v1.3.3...v1.3.4) (Apr 04, 2018)
12
+
13
+ ### Fixed
14
+
15
+ - Due to a load order issue, sometimes the main `ApplicationController` was used by this gem (unnecessary) [#82](https://github.com/fgrehm/letter_opener_web/pull/82)
16
+
17
+ ## [1.3.3](https://github.com/fgrehm/letter_opener_web/compare/v1.3.2...v1.3.3) (Jan 29, 2018)
18
+
19
+ - Set `LAUNCHY_DRY_RUN` explicitly to avoid `Launchy::CommandNotFoundError` [#75](https://github.com/fgrehm/letter_opener_web/pull/75)
20
+ - Update Ruby matrix for test to include more recent versions [#77](https://github.com/fgrehm/letter_opener_web/pull/77)
21
+
1
22
  ## [1.3.2](https://github.com/fgrehm/letter_opener_web/compare/v1.3.1...v1.3.2) (Jan 14, 2018)
2
23
 
3
24
  - Disable Launchy with ENV to avoid redefining the whole delivery method [#73](https://github.com/fgrehm/letter_opener_web/pull/73)
data/Gemfile CHANGED
@@ -6,3 +6,7 @@ source 'http://rubygems.org'
6
6
  # Bundler will treat runtime dependencies like base dependencies, and
7
7
  # development dependencies will be added by default to the :development group.
8
8
  gemspec
9
+
10
+ group :test do
11
+ gem 'codecov', require: false
12
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2014 Fabio Rehm
1
+ Copyright (c) 2013-2018 Fabio Rehm
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # letter_opener_web
2
2
 
3
- [![Build Status](https://travis-ci.org/fgrehm/letter_opener_web.png?branch=master)](https://travis-ci.org/fgrehm/letter_opener_web) [![Gem Version](https://badge.fury.io/rb/letter_opener_web.png)](http://badge.fury.io/rb/letter_opener_web) [![Code Climate](https://codeclimate.com/github/fgrehm/letter_opener_web.png)](https://codeclimate.com/github/fgrehm/letter_opener_web) [![Gitter chat](https://badges.gitter.im/fgrehm/letter_opener_web.png)](https://gitter.im/fgrehm/letter_opener_web)
3
+ [![Build Status](https://travis-ci.org/fgrehm/letter_opener_web.svg?branch=master)](https://travis-ci.org/fgrehm/letter_opener_web)
4
+ [![Gem Version](https://badge.fury.io/rb/letter_opener_web.svg)](http://badge.fury.io/rb/letter_opener_web)
5
+ [![Code Climate](https://codeclimate.com/github/fgrehm/letter_opener_web.svg)](https://codeclimate.com/github/fgrehm/letter_opener_web)
4
6
 
5
7
  Gives [letter_opener](https://github.com/ryanb/letter_opener) an interface for
6
8
  browsing sent emails.
@@ -13,7 +15,7 @@ First add the gem to your development environment and run the `bundle` command t
13
15
 
14
16
  ```ruby
15
17
  group :development do
16
- gem 'letter_opener_web'
18
+ gem 'letter_opener_web', '~> 1.0'
17
19
  end
18
20
  ```
19
21
 
@@ -23,9 +25,7 @@ Add to your routes.rb:
23
25
 
24
26
  ```ruby
25
27
  Your::Application.routes.draw do
26
- if Rails.env.development?
27
- mount LetterOpenerWeb::Engine, at: "/letter_opener"
28
- end
28
+ mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
29
29
  end
30
30
  ```
31
31
 
@@ -69,7 +69,7 @@ Some people use this gem on staging environments on Heroku and to set that up
69
69
  is just a matter of moving the gem out of the `development` group and enabling
70
70
  the route for all environments on your `routes.rb`.
71
71
 
72
- In order words, your `Gemfile` will have:
72
+ In other words, your `Gemfile` will have:
73
73
 
74
74
  ```ruby
75
75
  gem 'letter_opener_web'
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ unless Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled?
4
+ require_dependency 'letter_opener_web/application_controller'
5
+ end
6
+
3
7
  module LetterOpenerWeb
4
8
  class LettersController < ApplicationController
5
- before_action :check_style, only: [:show]
9
+ before_action :check_style, only: :show
6
10
  before_action :load_letter, only: %i[show attachment destroy]
7
11
 
8
12
  def index
@@ -22,6 +26,7 @@ module LetterOpenerWeb
22
26
  file = @letter.attachments[filename]
23
27
 
24
28
  return render plain: 'Attachment not found!', status: 404 unless file.present?
29
+
25
30
  send_file(file, filename: filename, disposition: 'inline')
26
31
  end
27
32
 
@@ -43,7 +48,8 @@ module LetterOpenerWeb
43
48
 
44
49
  def load_letter
45
50
  @letter = Letter.find(params[:id])
46
- head :not_found unless @letter.exists?
51
+
52
+ head :not_found unless @letter.valid?
47
53
  end
48
54
 
49
55
  def routes
@@ -56,17 +56,19 @@ module LetterOpenerWeb
56
56
  end
57
57
 
58
58
  def delete
59
- FileUtils.rm_rf("#{LetterOpenerWeb.config.letters_location}/#{id}")
59
+ return unless valid?
60
+
61
+ FileUtils.rm_rf(base_dir.to_s)
60
62
  end
61
63
 
62
- def exists?
63
- File.exist?(base_dir)
64
+ def valid?
65
+ exists? && base_dir_within_letters_location?
64
66
  end
65
67
 
66
68
  private
67
69
 
68
70
  def base_dir
69
- "#{LetterOpenerWeb.config.letters_location}/#{id}"
71
+ LetterOpenerWeb.config.letters_location.join(id).cleanpath
70
72
  end
71
73
 
72
74
  def read_file(style)
@@ -77,6 +79,14 @@ module LetterOpenerWeb
77
79
  File.exist?("#{base_dir}/#{style}.html")
78
80
  end
79
81
 
82
+ def exists?
83
+ File.exist?(base_dir)
84
+ end
85
+
86
+ def base_dir_within_letters_location?
87
+ base_dir.to_s.start_with?(LetterOpenerWeb.config.letters_location.to_s)
88
+ end
89
+
80
90
  def adjust_link_targets(contents)
81
91
  # We cannot feed the whole file to an XML parser as some mails are
82
92
  # "complete" (as in they have the whole <html> structure) and letter_opener
@@ -86,6 +96,7 @@ module LetterOpenerWeb
86
96
  fixed_link = fix_link_html(link)
87
97
  xml = REXML::Document.new(fixed_link).root
88
98
  next if xml.attributes['href'] =~ /(plain|rich).html/
99
+
89
100
  xml.attributes['target'] = '_blank'
90
101
  xml.add_text('') unless xml.text
91
102
  contents.gsub!(link, xml.to_s)