Redcarpet and Pygments

  • add the following gems

    1
    2
    gem 'redcarpet', '~> 3.3', '>= 3.3.4'
    gem 'pygments.rb', '~> 0.6.3'
  • create pygments.css.erb file and add

1
2
3
4
5
6
<%= Pygments.css(:style => "colorful")  %>

// You can also try 'transparent' in place of #212325
.highlight pre {
background-color: #212325;
}
  • open application_helper.rb and add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

module ApplicationHelper
#Pygments
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
sha = Digest::SHA1.hexdigest(code)
Rails.cache.fetch ["code", language, sha].join('-') do
Pygments.highlight(code, lexer: language)
end
end
end

# Redcarpet

def markdown(text)
renderer = HTMLwithPygments.new(hard_wrap: true, filter_html: true)
options = {
autolink: true,
no_intra_emphasis: true,
fenced_code_blocks: true,
lax_html_blocks: true,
strikethrough: true,
superscript: true
}
Redcarpet::Markdown.new(renderer, options).render(text).html_safe
end
end

How to Add a Custom Domain

Today I deployed a couple of web applications to Heroku and used Google Domains as my domain host. Every once in a while I have to do this and I often end up spending a good amount of time looking up documentation on how to add custom domains to Heroku. To save time for next time, I’ve compiled this blog for me and other Rails developers who might find themselves in a similar situation. This blog assumes you have a Ruby on Rails application already deployed to Heroku and a domain name hosted at Google Domains. If you need help deploying your app to Heroku, I would recommend the fantastic Ruby on Rails Tutorial by Michael Hartl. Otherwise, lets get started.

  • Add your domain using the command below in your terminal
1
$ heroku domains:add www.your_domain.com
  • Retrieve your DNS Target which you’ll need for Google Domains by running the code below in your terminal.
1
$ heroku domains
  • You should see somethings like the code below.
1
2
3
4
5
6
7
=== your_heroku_appname Heroku Domain
appname.herokuapp.com

=== your_heroku_appname Custom Domains
Domain Name DNS Target
────────────── ────────────────────────────
www.yourdomain.com www.yourdomain.herokudns.com
  • Next Log into your domains.google.com
  • Click on Configure DNS
  • Next find the Synthetic records section and do the following

    1. Make sure the dropdown is selected for Subdomain forward
    2. Add @ in the subdomain box
    3. Add www.your_domain.com in the Destination URL
    4. Click on the Add button
  • Next find the Custom resource records section and do the following

  1. Type www in the first box
  2. Select CNAME from the dropdown menu
  3. Type in the DNS Target you retrieved from Heroku into the last box that says Domain Name. If you don’t have it go to your terminal and run this
1
$ heroku domains
  • It will look something like this www.example.com.herokudns.com

I hope this helps, if you have any questions or comments, please click on the Contact link below and send me an email.