automaildoc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e2aee9768896ee327fc454752fc826e7121ca4c
4
+ data.tar.gz: 1607512fc35ea229cc242a3fa143dd2b9ed56b92
5
+ SHA512:
6
+ metadata.gz: fb80f8fd9d306dadde60b47a0b6d22fee6229e8bae4b61b0bebc530bba6ec844675916592a4cc0a0d16f83edfbf595c2144143bcb6a7ef32681214e6ba3b2a30
7
+ data.tar.gz: b2a4e6073171cb5a480af43a0002be58ed800a69be92fb142e380c61d6a61caf71df5feda5838ee61109572e04d646bc438fd4dc97e5c8889636f0486bc1e095
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.4
6
+ script:
7
+ - bundle exec rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Change Log
2
+
3
+ ### 0.1.0
4
+
5
+ - First release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in automaildoc.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 ohbarye
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Automaildoc
2
+
3
+ [![Build Status](https://travis-ci.org/ohbarye/automaildoc.svg?branch=master)](https://travis-ci.org/ohbarye/automaildoc)
4
+
5
+ Automaildoc is a gem to generate a list of about mails from your mail spec.
6
+
7
+ ![image](https://user-images.githubusercontent.com/1811616/29994119-f963a9d2-9002-11e7-990f-cf71add83b4d.png)
8
+
9
+ This gem, idea, design all are completely inspired by the awesome predecessor, https://github.com/r7kamura/autodoc.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'automaildoc', group: :test
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```console
22
+ $ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```console
28
+ $ gem install automaildoc
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ 1. Add a `automaildoc` tag to your mail spec.
34
+
35
+ ```ruby
36
+ RSpec.describe 'Sign up mail', automaildoc: true do
37
+ let!(:user) { create(:user) }
38
+ let!(:mail) { SignupMailer.mail(user) }
39
+
40
+ it 'should send to a user' do
41
+ expect(mail.to).to eq user
42
+ end
43
+ end
44
+ ```
45
+
46
+ 2. Run rspec test with `AUTOMAILDOC`
47
+
48
+ ```console
49
+ $ AUTOMAILDOC=1 bundle exec rspec
50
+ ```
51
+
52
+ That's it. Then Automaildoc generates an HTML file to `./doc/mails`. The file should be what you've wanted.
53
+
54
+ ![automaildoc](https://user-images.githubusercontent.com/1811616/29994112-c6dacbc6-9002-11e7-812f-a346d415d6c4.gif)
55
+
56
+ ### Example
57
+
58
+ You can see `spec/dummy/doc/toc.html` in this repository, which is auto-generated one from mail specs in `spec/mails`.
59
+
60
+ ### Configuration
61
+
62
+ - path - [String] location to put files (default: `./doc/mails`)
63
+ - html_template - [String] ERB template for a mail (default: `./automaildoc/templates/mail.html.erb`)
64
+ - toc_html_template - [String] ERB template for table of content (default: `./automaildoc/templates/toc.html.erb`)
65
+
66
+ ```ruby
67
+ Automaildoc.configuration.path = "doc/mails"
68
+ Automaildoc.configuration.html_template = File.read(File.expand_path("../automaildoc/templates/mail.html.erb", __FILE__))
69
+ Automaildoc.configuration.toc_html_template = File.read(File.expand_path("../automaildoc/templates/toc.html.erb", __FILE__))
70
+ ```
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ohbarye/automaildoc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "automaildoc/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "automaildoc"
8
+ spec.version = Automaildoc::VERSION
9
+ spec.authors = ["Masato Ohba"]
10
+ spec.email = ["over.rye@gmail.com"]
11
+
12
+ spec.summary = "Generate mail preview from your mail spec"
13
+ spec.description = "Automaildoc is a gem to generate a list of about mails from your mail spec."
14
+ spec.homepage = "https://github.com/ohbarye/automaildoc"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "rspec"
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "mail"
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "automaildoc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ require "automaildoc/configuration"
2
+ require "automaildoc/document"
3
+ require "automaildoc/documents"
4
+ require "automaildoc/version"
5
+ require "automaildoc/rspec" if ENV["AUTOMAILDOC"]
6
+
7
+ module Automaildoc
8
+ class << self
9
+ def documents
10
+ @documents ||= Documents.new
11
+ end
12
+
13
+ def configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ module Automaildoc
2
+ class Configuration
3
+ class << self
4
+ def property(name, &default)
5
+ define_method(name) do
6
+ if instance_variable_defined?("@#{name}")
7
+ instance_variable_get("@#{name}")
8
+ else
9
+ instance_variable_set("@#{name}", instance_exec(&default))
10
+ end
11
+ end
12
+
13
+ attr_writer name
14
+ end
15
+ end
16
+
17
+ property :path do
18
+ "doc/mails"
19
+ end
20
+
21
+ property :html_template do
22
+ File.read(File.expand_path("../templates/mail.html.erb", __FILE__))
23
+ end
24
+
25
+ property :toc_html_template do
26
+ File.read(File.expand_path("../templates/toc.html.erb", __FILE__))
27
+ end
28
+
29
+ def pathname
30
+ Pathname.new(path)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ require 'erb'
2
+
3
+ module Automaildoc
4
+ class Document
5
+ def initialize(context, example)
6
+ @context = context
7
+ @example = example
8
+ end
9
+
10
+ def render
11
+ ERB.new(Automaildoc.configuration.html_template, nil, '-').result(binding)
12
+ end
13
+
14
+ def id
15
+ @example.id
16
+ end
17
+
18
+ def description
19
+ @example.full_description
20
+ end
21
+
22
+ def mail
23
+ @context.mail
24
+ end
25
+
26
+ def to
27
+ mail.to || []
28
+ end
29
+
30
+ def cc
31
+ mail.cc || []
32
+ end
33
+
34
+ def bcc
35
+ mail.bcc || []
36
+ end
37
+
38
+ def subject
39
+ mail.subject || ''
40
+ end
41
+
42
+ def body
43
+ mail.body || ''
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,33 @@
1
+ require "pathname"
2
+
3
+ module Automaildoc
4
+ class Documents
5
+ def initialize
6
+ @mails = []
7
+ end
8
+
9
+ def append(context, example)
10
+ mail = Automaildoc::Document.new(context.clone, example.clone)
11
+ (@mails << mail).sort_by(&:subject)
12
+ end
13
+
14
+ def write
15
+ write_toc_html
16
+ end
17
+
18
+ private
19
+
20
+ def write_toc_html
21
+ toc_html_path.parent.mkpath
22
+ toc_html_path.open("w") {|file| file << render_toc_html }
23
+ end
24
+
25
+ def render_toc_html
26
+ ERB.new(Automaildoc.configuration.toc_html_template, nil, "-").result(binding)
27
+ end
28
+
29
+ def toc_html_path
30
+ Automaildoc.configuration.pathname + "toc.html"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ require "rspec"
2
+
3
+ RSpec.configuration.after(:each, automaildoc: true) do |example|
4
+ Automaildoc.documents.append(self, example) unless example.pending?
5
+ end
6
+
7
+ RSpec.configuration.after(:suite) do
8
+ Automaildoc.documents.write
9
+ end
@@ -0,0 +1,25 @@
1
+ <div id="<%= id %>" class="mail">
2
+ <h3><%= description %></h3>
3
+ <div class="row">
4
+ TO:
5
+ <% to.each do |mail| %>
6
+ <span class="badge badge-default"><%= mail %></span>
7
+ <% end %>
8
+ </div>
9
+ <div class="row">
10
+ CC:
11
+ <% cc.each do |mail| %>
12
+ <span class="badge badge-default"><%= mail %></span>
13
+ <% end %>
14
+ </div>
15
+ <div class="row">
16
+ BCC:
17
+ <% bcc.each do |mail| %>
18
+ <span class="badge badge-default"><%= mail %></span>
19
+ <% end %>
20
+ </div>
21
+ <pre><%= subject %></pre>
22
+ <pre><%= body %></pre>
23
+ </div>
24
+
25
+ <hr>
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html lang="ja">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6
+ <style>
7
+ body {
8
+ font-family: -apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
9
+ }
10
+ .badge-default {
11
+ background-color: #636c72;
12
+ }
13
+ .badge {
14
+ display: inline-block;
15
+ padding: .25em .4em;
16
+ font-size: 75%;
17
+ font-weight: 700;
18
+ line-height: 1;
19
+ color: #fff;
20
+ text-align: center;
21
+ white-space: nowrap;
22
+ vertical-align: baseline;
23
+ border-radius: .25rem;
24
+ }
25
+ h2 {
26
+ margin-top: 16px;
27
+ margin-bottom: 16px;
28
+ font-size: 2rem;
29
+ font-weight: 500;
30
+ }
31
+ h3 {
32
+ margin-top: 16px;
33
+ margin-bottom: 16px;
34
+ font-size: 1.75rem;
35
+ font-weight: 500;
36
+ color: gray;
37
+ }
38
+ pre {
39
+ word-break: break-all;
40
+ white-space: pre;
41
+ white-space: pre-wrap;
42
+ white-space: pre-line;
43
+ white-space: -pre-wrap;
44
+ white-space: -o-pre-wrap;
45
+ white-space: -moz-pre-wrap;
46
+ white-space: -hp-pre-wrap;
47
+ word-wrap: break-word;
48
+ background-color: rgb(247, 247, 249);
49
+ padding: 1em;
50
+ font-family: Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
51
+ font-size: 90%;
52
+ }
53
+ .container {
54
+ padding: 24px 16px;
55
+ }
56
+ .row {
57
+ display: block;
58
+ margin: 8px 0px;
59
+ }
60
+ .container .row .col-sm-4 {
61
+ margin: 0px -8px;
62
+ padding: 0px 8px;
63
+ vertical-align: top;
64
+ display: inline-block;
65
+ }
66
+ @media screen and (min-width:768px) {
67
+ .container .row .col-sm-4 {
68
+ width: 33%;
69
+ }
70
+ }
71
+ .container .row .col-sm-8 {
72
+ margin: 0px -8px;
73
+ padding: 0px 8px;
74
+ vertical-align: top;
75
+ display: inline-block;
76
+ }
77
+ @media screen and (min-width:768px) {
78
+ .container .row .col-sm-8 {
79
+ width: 66%;
80
+ }
81
+ }
82
+ hr {
83
+ margin: 16px 0px
84
+ }
85
+ </style>
86
+ </head>
87
+ <body>
88
+ <div class="container">
89
+ <div class="row">
90
+ <div class="col-sm-4">
91
+ <h2>Mail List</h2>
92
+ <ul>
93
+ <% @mails.each do |mail| %>
94
+ <li>
95
+ <a href="#<%= mail.id %>"><%= mail.subject %></a>
96
+ </li>
97
+ <% end %>
98
+ </ul>
99
+ </div>
100
+
101
+ <div class="col-sm-8">
102
+ <h2>Mail Details</h2>
103
+ <% @mails.each do |mail| %>
104
+ <%= mail.render %>
105
+ <% end %>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ </body>
110
+ </html>
@@ -0,0 +1,3 @@
1
+ module Automaildoc
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: automaildoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masato Ohba
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mail
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Automaildoc is a gem to generate a list of about mails from your mail
84
+ spec.
85
+ email:
86
+ - over.rye@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CHANGELOG.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - automaildoc.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/automaildoc.rb
103
+ - lib/automaildoc/configuration.rb
104
+ - lib/automaildoc/document.rb
105
+ - lib/automaildoc/documents.rb
106
+ - lib/automaildoc/rspec.rb
107
+ - lib/automaildoc/templates/mail.html.erb
108
+ - lib/automaildoc/templates/toc.html.erb
109
+ - lib/automaildoc/version.rb
110
+ homepage: https://github.com/ohbarye/automaildoc
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.13
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Generate mail preview from your mail spec
134
+ test_files: []