malina 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ddf49f09e26acd295056933f597683e0a17423db3ff0e3070bbe458856bf8acb
4
+ data.tar.gz: 3a734030fbd633bdfe9375a835c0e39cd8de285eae7582939e9b58e16602a66a
5
+ SHA512:
6
+ metadata.gz: faa17c418c39e864987f76f3a5f93a2def156b8c79c2892143177259f33d7a25029b88653436830438ce27e99d0dfe112e7440b8fe38c1ff28aecb642e7e74b5
7
+ data.tar.gz: 7e63bd7f572173ffa80f3cf27010ba696a634b65ca0265fdbaf7c6471d4aff540c207446c2d919b8586d24406b71b712b4cc7637aeeb09cf32beb8ffc7444a71
@@ -0,0 +1,20 @@
1
+ Copyright 2019 mpakus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # Malina
2
+ [![CircleCI](https://circleci.com/gh/mpakus/malina.svg?style=svg)](https://circleci.com/gh/mpakus/malina)
3
+
4
+ Interface for browsing sent emails.
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'malina', group: :development
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ $ gem install malina
21
+ ```
22
+
23
+ ### 1. Generate initialize file
24
+
25
+ ```bash
26
+ rails g malina:install
27
+ ```
28
+
29
+ it generates `malina_emails.rb` in your application's folder `config/initializers/`
30
+ ```ruby
31
+ ActionMailer::Base.register_interceptor(Malina::EmailInterceptor) if Rails.env.development?
32
+
33
+ Malina::Config.layout = 'malina'
34
+ ```
35
+
36
+ ### 2. Generate migration file
37
+
38
+ ```bash
39
+ rails g malina:migration
40
+ ```
41
+
42
+ run migration
43
+ ```bash
44
+ rails db:migrate
45
+ ```
46
+
47
+ ### 3. Mount route
48
+ add this line to your `config/routes.rb`
49
+
50
+ ```ruby
51
+ mount Malina::Engine => '/backroom/emails', as: :malina
52
+ ```
53
+ you can change this url of course
54
+
55
+ ## Usage
56
+
57
+ and now interface is available at your's app url, for example `localhost:3000/backroom/emails`
58
+
59
+ ![Alt text](https://monosnap.com/image/L4OXErEzGxTbtT262b8P8XPqmGoz9L)
60
+
61
+ ![Alt text](https://monosnap.com/image/dDrVpfW9PP6ixMZlJqeUVBQGa1MUgW)
62
+
63
+ ## Views
64
+
65
+ Since Malina is an engine, all its views are packaged inside the gem.
66
+ These views will help you get started, but after some time you may want to change them.
67
+ If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
68
+
69
+ ```bash
70
+ rails g malina:layout
71
+ ```
72
+ makes Layout available for changes
73
+
74
+ ```bash
75
+ rails g malina:views
76
+ ```
77
+ the other views, too
78
+
79
+ ## Contributing
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mpakus/malina
81
+
82
+ ## License
83
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'Malina'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
18
+
19
+ APP_RAKEFILE = File.expand_path('spec/internal/Rakefile', __dir__)
20
+ load 'rails/tasks/engine.rake'
21
+
22
+ load 'rails/tasks/statistics.rake'
23
+
24
+ require 'bundler/gem_tasks'
25
+
26
+ require 'rake/testtask'
27
+
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'lib'
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+ task default: :test
File without changes
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Malina::EmailsController < ApplicationController
4
+ layout Malina::Config.layout
5
+
6
+ def destroy
7
+ Malina::Email.destroy_all
8
+ redirect_to malina.malina_emails_path
9
+ end
10
+
11
+ private
12
+
13
+ # @return [Array<Malina::Email>]
14
+ def emails
15
+ @emails ||= Malina::Email.ordered
16
+ end
17
+
18
+ # @return [Malina::Email]
19
+ def email
20
+ @email ||= Malina::Email.find(params[:id])
21
+ end
22
+
23
+ # @param [String] emails
24
+ # @return [String]
25
+ def prepare(emails = nil)
26
+ return '' unless emails
27
+
28
+ JSON.parse(emails)&.join(', ')
29
+ end
30
+
31
+ helper_method :emails
32
+ helper_method :email
33
+ helper_method :prepare
34
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Malina::Email < ActiveRecord::Base
4
+ self.table_name = 'malina_emails'
5
+
6
+ scope :ordered, -> { order(created_at: :desc) }
7
+ end
8
+ # == Schema Information
9
+ #
10
+ # Table name: malina_emails
11
+ #
12
+ # id :integer not null, primary key
13
+ # bcc :string
14
+ # body :text
15
+ # cc :string
16
+ # from :string
17
+ # subject :string
18
+ # to :string
19
+ # created_at :datetime not null
20
+ # updated_at :datetime not null
21
+ #
22
+ # Indexes
23
+ #
24
+ # index_malina_emails_on_from (from)
25
+ # index_malina_emails_on_to (to)
26
+ #
27
+
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Malina::Config
4
+ @layout = 'malina'
5
+
6
+ class << self
7
+ attr_accessor :layout
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Malina::EmailInterceptor
4
+ def self.delivering_email(message)
5
+ Malina::Email.create(
6
+ subject: message.subject,
7
+ to: message.to,
8
+ from: message.from,
9
+ cc: message.cc,
10
+ bcc: message.bcc,
11
+ body: message.body
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <title>
5
+ E-mails
6
+ </title>
7
+ <style>
8
+ body {
9
+ background: #fff;
10
+ font-size: 12px;
11
+ font-family: "Helvetica Neue", Arial, sans-serif;
12
+ padding: 1em;
13
+ margin: 0;
14
+ height: 100%;
15
+ overflow: auto;
16
+ }
17
+
18
+ table.malina-table {
19
+ width: 100%;
20
+ }
21
+
22
+ table.malina-table > thead {
23
+ border-top: 1px solid #000;
24
+ border-bottom: 1px solid #000;
25
+ }
26
+
27
+ table.malina-table td {
28
+ padding: 0.3em;
29
+ }
30
+
31
+ iframe.malina-email-body {
32
+ border: 0;
33
+ width: 100%;
34
+ height: 100%;
35
+
36
+ white-space: pre-wrap;
37
+ border: 1px solid #eee;
38
+ }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <div class="malina-container">
43
+ <%= yield %>
44
+ </div>
45
+ </body>
46
+ </html>
@@ -0,0 +1,32 @@
1
+ <h1>E-mails</h1>
2
+
3
+ <p class="malina-clear-button">
4
+ <%= button_to 'Clear all', malina.malina_email_path(1), method: :delete %>
5
+ </p>
6
+
7
+ <table class="malina-table">
8
+ <thead>
9
+ <tr>
10
+ <th>ID</th>
11
+ <th>When</th>
12
+ <th>From</th>
13
+ <th>To</th>
14
+ <th>Subject</th>
15
+ <th>CC</th>
16
+ <th>BCC</th>
17
+ </tr>
18
+ </thead>
19
+ <tbody>
20
+ <% emails.each do |email| %>
21
+ <tr>
22
+ <td><%= link_to email.id, malina.malina_email_path(email) %></td>
23
+ <td><%= l email.created_at %></td>
24
+ <td><%= link_to email.subject, malina.malina_email_path(email) %></td>
25
+ <td><%= prepare email.from %></td>
26
+ <td><%= prepare email.to %></td>
27
+ <td><%= prepare email.cc %></td>
28
+ <td><%= prepare email.bcc %></td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
@@ -0,0 +1,13 @@
1
+ <h1>E-mail</h1>
2
+
3
+ <p class="malina-back-button">
4
+ <%= link_to '<< Back', malina.malina_emails_path %>
5
+ </p>
6
+
7
+ <div class="malina-email">
8
+ <h3>Subject: <%= email.subject %></h3>
9
+ <h4>From: <%= prepare email.from %></h4>
10
+ <h4>To: <%= prepare email.to %></h4>
11
+ <hr>
12
+ <iframe class="malina-email-body" seamless="seamless" srcdoc="<%= email.body %>" onload="this.style.height=this.contentDocument.body.scrollHeight +'px';"></iframe>
13
+ </div>
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rails.application.routes.draw do
4
+ # root to: 'malina/emails#index'
5
+ #
6
+ # namespace :malina do
7
+ # resources :emails, only: %i[index show destroy]
8
+ # end
9
+ # end
10
+
11
+ Malina::Engine.routes do
12
+ root to: 'malina/emails#index'
13
+
14
+ namespace :malina do
15
+ resources :emails, only: %i[index show destroy]
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Malina
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __dir__)
6
+
7
+ desc 'Configure necessary files to use Malina E-mails'
8
+ def copy_initializer_file
9
+ copy_file 'malina_emails.rb', Rails.root.join('config/initializers/malina_emails.rb')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Malina
4
+ class LayoutGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../app/views/layouts', __dir__)
6
+
7
+ desc 'Copy layout file'
8
+ def copy_views_file
9
+ copy_file 'malina.html.erb', Rails.root.join('app/views/layouts/malina.html.erb')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Malina
4
+ class MigrationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root File.expand_path('../templates', __dir__)
7
+
8
+ def self.next_migration_number(dirname)
9
+ return Time.new.utc.strftime('%Y%m%d%H%M%S') if ActiveRecord::Base.timestamped_migrations
10
+
11
+ format('%.3d', (current_migration_number(dirname) + 1))
12
+ end
13
+
14
+ def create_migration_file
15
+ migration_template 'create_malina_emails.rb', 'db/migrate/create_malina_emails.rb'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Malina
4
+ class ViewsGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __dir__)
6
+
7
+ desc 'Copy views files'
8
+ def copy_views_file
9
+ copy_file 'index.html.erb', Rails.root.join('app/views/malina/emails/index.html.erb')
10
+ copy_file 'show.html.erb', Rails.root.join('app/views/malina/emails/show.html.erb')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateMalinaEmails < ActiveRecord::Migration[5.0]
4
+ def change
5
+ create_table :malina_emails do |t|
6
+ t.string :subject
7
+ t.string :to, index: true
8
+ t.string :from, index: true
9
+ t.string :cc
10
+ t.string :bcc
11
+ t.text :body
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActionMailer::Base.register_interceptor(Malina::EmailInterceptor) if Rails.env.development?
4
+
5
+ Malina::Config.layout = 'malina'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'malina/engine'
4
+
5
+ module Malina
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Malina
4
+ class Engine < ::Rails::Engine
5
+ # isolate_namespace Malina
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Malina
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # desc "Explaining what the task does"
4
+ # task :malina do
5
+ # # Task goes here
6
+ # end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: malina
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Renat "MpaK" Ibragimov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5.0'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: combustion
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-rails
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.49'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.49'
103
+ - !ruby/object:Gem::Dependency
104
+ name: sqlite3
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.6
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 1.3.6
117
+ description: Interface for browsing sent emails.
118
+ email:
119
+ - mrak69@gmail.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - MIT-LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - app/assets/config/malina_manifest.js
128
+ - app/controllers/malina/emails_controller.rb
129
+ - app/models/malina/email.rb
130
+ - app/services/malina/config.rb
131
+ - app/services/malina/email_interceptor.rb
132
+ - app/views/layouts/malina.html.erb
133
+ - app/views/malina/emails/index.html.erb
134
+ - app/views/malina/emails/show.html.erb
135
+ - config/routes.rb
136
+ - lib/generators/malina/install_generator.rb
137
+ - lib/generators/malina/layout_generator.rb
138
+ - lib/generators/malina/migration_generator.rb
139
+ - lib/generators/malina/views_generator.rb
140
+ - lib/generators/templates/create_malina_emails.rb
141
+ - lib/generators/templates/malina_emails.rb
142
+ - lib/malina.rb
143
+ - lib/malina/engine.rb
144
+ - lib/malina/version.rb
145
+ - lib/tasks/malina_tasks.rake
146
+ homepage: https://github.com/mpakus/malina
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ changelog_uri: https://github.com/mpakus/malina/blob/master/CHANGELOG.md
151
+ documentation_uri: https://github.com/mpakus/malina
152
+ homepage_uri: https://github.com/mpakus/malina
153
+ source_code_uri: https://github.com/mpakus/malina
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubygems_version: 3.0.4
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Malina E-mails UI as Rails Engine
173
+ test_files: []