Skip to content

Commit

Permalink
FIXES#62 - Add StandardRB
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakmahakale committed Sep 16, 2022
1 parent 9b92acb commit afbd8c0
Show file tree
Hide file tree
Showing 38 changed files with 121 additions and 145 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Linter

on:
- push
- pull_request

jobs:
check-changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.0
bundler-cache: true
- name: Bundle install
run: |
gem install bundler
bundle install --jobs 4 --retry 3 --path vendor/bundle
- name: Run Linter
run: bundle exec standardrb
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
appraise "rails_5_2" do
gem "rails", "5.2.3"
gem "sqlite3", "~> 1.4"
gem 'net-smtp', require: false
gem "net-smtp", require: false
end

appraise "rails_6_0" do
gem "rails", "6.0.5"
gem "sqlite3", "~> 1.4"
gem 'net-smtp', require: false
gem "net-smtp", require: false
end

appraise "rails_6_1" do
gem "rails", "6.1.6"
gem "sqlite3", "~> 1.4"
gem 'net-smtp', require: false
gem "net-smtp", require: false
end

appraise "rails_7_0" do
Expand Down
28 changes: 13 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
begin
require 'bundler/setup'
require "bundler/setup"
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
end

require 'rdoc/task'
require "rdoc/task"

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Maildown'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_dir = "rdoc"
rdoc.title = "Maildown"
rdoc.options << "--line-numbers"
rdoc.rdoc_files.include("README.md")
rdoc.rdoc_files.include("lib/**/*.rb")
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'

load "rails/tasks/engine.rake"

Bundler::GemHelper.install_tasks

require 'rake/testtask'
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.libs << "lib"
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end


task default: :test

require "bundler/gem_tasks"
10 changes: 5 additions & 5 deletions lib/maildown.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Top level module, all module methods are used for configuration
module Maildown
@allow_indentations = false
@enable_layouts = false
@enable_layouts = false

def self.allow_indentation
@allow_indentations
Expand All @@ -16,11 +16,11 @@ def self.rails_6?
end
end

require 'maildown/markdown_engine'
require "maildown/markdown_engine"
ActiveSupport.on_load(:action_mailer) do
require 'maildown/ext/action_mailer'
require "maildown/ext/action_mailer"
end
ActiveSupport.on_load(:action_view) do
require 'maildown/ext/action_view'
require "maildown/ext/action_view"
end
require 'maildown/handlers/markdown'
require "maildown/handlers/markdown"
10 changes: 5 additions & 5 deletions lib/maildown/ext/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# This monkeypatch detects when a markdown email is being
# used and generates both a markdown and text template
class ActionMailer::Base
alias :original_each_template :each_template
alias_method :original_each_template, :each_template

def each_template(paths, name, &block)
templates = original_each_template(paths, name, &block)
Expand All @@ -44,8 +44,8 @@ def each_template(paths, name, &block)
html_template = templates.first

# Cached template is already defined
if html_template.instance_variable_defined?(:"@maildown_text_template")
text_template = html_template.instance_variable_get(:"@maildown_text_template")
if html_template.instance_variable_defined?(:@maildown_text_template)
text_template = html_template.instance_variable_get(:@maildown_text_template)
return [html_template, text_template]
end

Expand All @@ -66,8 +66,8 @@ def each_template(paths, name, &block)
text_template.formats = formats
end

html_template.instance_variable_set(:"@maildown_text_template", text_template)
html_template.instance_variable_set(:@maildown_text_template, text_template)

return [html_template, text_template]
[html_template, text_template]
end
end
8 changes: 4 additions & 4 deletions lib/maildown/ext/action_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ def extract_handler_and_format_and_variant(template)
# in addition to `.md+erb` and `.md`
module ActionView
class OptimizedFileSystemResolver
alias :original_extract_handler_and_format_and_variant :extract_handler_and_format_and_variant
alias_method :original_extract_handler_and_format_and_variant, :extract_handler_and_format_and_variant

# Different versions of rails have different
# method signatures here, path is always first
def extract_handler_and_format_and_variant(*args)
if args.first.end_with?('md.erb')
if args.first.end_with?("md.erb")
path = args.shift
path = path.gsub(/\.md\.erb\z/, '.md+erb')
path = path.gsub(/\.md\.erb\z/, ".md+erb")
args.unshift(path)
end
return original_extract_handler_and_format_and_variant(*args)
original_extract_handler_and_format_and_variant(*args)
end
end
end
7 changes: 4 additions & 3 deletions lib/maildown/handlers/markdown.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'action_view'

require "action_view"

module Maildown
module Handlers
Expand Down Expand Up @@ -32,7 +33,7 @@ def self.call(template, source = nil)

# Match beginning whitespace but not newline
# http://rubular.com/r/uCXQ58OOC8
source.gsub!(/^[^\S\n]+/, ''.freeze) if Maildown.allow_indentation
source.gsub!(/^[^\S\n]+/, "") if Maildown.allow_indentation

if Maildown.rails_6?
compiled_source = erb_handler.call(template, source)
Expand All @@ -55,7 +56,7 @@ def self.call(template, source = nil)
# Allows for templates like `contact.md` or `contact.md+erb` to be rendered as
# markdown.
ActionView::Template.register_template_handler :"md+erb", Maildown::Handlers::Markdown
ActionView::Template.register_template_handler :"md", Maildown::Handlers::Markdown
ActionView::Template.register_template_handler :md, Maildown::Handlers::Markdown

# Used in conjunction with ext/action_view.rb monkey patch
# to allow for using the ".md.erb" file "extension".
Expand Down
2 changes: 1 addition & 1 deletion lib/maildown/markdown_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ def self.default_text_block
end
end

Maildown::MarkdownEngine.autoload(:"Kramdown", "kramdown")
Maildown::MarkdownEngine.autoload(:Kramdown, "kramdown")
16 changes: 8 additions & 8 deletions maildown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ require "maildown/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "maildown"
s.version = Maildown::VERSION
s.authors = ["schneems"]
s.email = ["[email protected]"]
s.homepage = "https://www.github.com/schneems/maildown"
s.summary = "Markdown in your mailbox"
s.name = "maildown"
s.version = Maildown::VERSION
s.authors = ["schneems"]
s.email = ["[email protected]"]
s.homepage = "https://www.github.com/schneems/maildown"
s.summary = "Markdown in your mailbox"
s.description = "Best practice is to send text/plain && text/html markdown works great for both, so why write your templates twices?"
s.license = "MIT"
s.license = "MIT"

s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]

s.add_dependency "actionmailer", ">= 4.0.0"
s.add_dependency "kramdown-parser-gfm"
Expand All @@ -24,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "m"
s.add_development_dependency "sqlite3"
s.add_development_dependency "rake"
s.add_development_dependency "standard"
end
2 changes: 1 addition & 1 deletion test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require File.expand_path("../config/application", __FILE__)

Dummy::Application.load_tasks
1 change: 0 additions & 1 deletion test/dummy/app/controllers/handlers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class HandlersController < ApplicationController

def show
render params[:id]
end
Expand Down
3 changes: 1 addition & 2 deletions test/dummy/app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
default from: "[email protected]"
end

16 changes: 8 additions & 8 deletions test/dummy/app/mailers/user_no_layout_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ class UserNoLayoutMailer < ApplicationMailer

def welcome
mail(
to: "[email protected]",
to: "[email protected]",
reply_to: "[email protected]",
subject: "hello world"
subject: "hello world"
)
end

def leading_whitespace
mail(
to: "[email protected]",
to: "[email protected]",
reply_to: "[email protected]",
subject: "hello world"
subject: "hello world"
)
end

def leading_whitespace_again
mail(
to: "[email protected]",
to: "[email protected]",
reply_to: "[email protected]",
subject: "hello world"
subject: "hello world"
)
end

def contact
mail(
to: "[email protected]",
to: "[email protected]",
reply_to: "[email protected]",
subject: "hello world"
subject: "hello world"
)
end
end
4 changes: 2 additions & 2 deletions test/dummy/app/mailers/user_with_layout_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class UserWithLayoutMailer < ApplicationMailer

def welcome
mail(
to: "[email protected]",
to: "[email protected]",
reply_to: "[email protected]",
subject: "hello world"
subject: "hello world"
)
end
end
4 changes: 2 additions & 2 deletions test/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
load Gem.bin_path("bundler", "bundle")
6 changes: 3 additions & 3 deletions test/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
APP_PATH = File.expand_path("../../config/application", __FILE__)
require_relative "../config/boot"
require "rails/commands"
4 changes: 2 additions & 2 deletions test/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
require_relative "../config/boot"
require "rake"
Rake.application.run
2 changes: 1 addition & 1 deletion test/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path("../config/environment", __FILE__)
run Rails.application
5 changes: 2 additions & 3 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path('../boot', __FILE__)
require File.expand_path("../boot", __FILE__)

require 'rails/all'
require "rails/all"

Bundler.require(*Rails.groups)
require "maildown"
Expand All @@ -20,4 +20,3 @@ class Application < Rails::Application
# config.i18n.default_locale = :de
end
end

6 changes: 3 additions & 3 deletions test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../../Gemfile", __FILE__)

require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
Loading

0 comments on commit afbd8c0

Please sign in to comment.