Skip to content

Commit

Permalink
Merge pull request #286 from realm/copyright
Browse files Browse the repository at this point in the history
support custom copyright markdown
  • Loading branch information
jpsim committed Aug 27, 2015
2 parents 4ba3689 + 0d9a451 commit 8c89cd9
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* Added support for custom assets: pass `--assets-directory` to jazzy.
[gurkendoktor](https://github.com/gurkendoktor)

* Added support for custom copyright text: pass `--copyright` to jazzy.
[emaloney](https://github.com/emaloney)

##### Bug Fixes

* Fixed a crash when parsing an empty documentation comment.
Expand Down
6 changes: 6 additions & 0 deletions lib/jazzy/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Config
attr_accessor :template_directory
attr_accessor :swift_version
attr_accessor :assets_directory
attr_accessor :copyright

def initialize
PodspecDocumenter.configure(self, Dir['*.podspec{,.json}'].first)
Expand Down Expand Up @@ -202,6 +203,11 @@ def self.parse!
exit
end

opt.on('--copyright COPYRIGHT_MARKDOWN', 'copyright markdown ' \
'rendered at the bottom of the docs pages') do |copyright|
config.copyright = copyright
end

opt.on('-h', '--help', 'Print this help message') do
puts opt
exit
Expand Down
24 changes: 12 additions & 12 deletions lib/jazzy/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
require 'pathname'
require 'mustache'

require 'jazzy/config'
require 'jazzy/gem_version'
require 'jazzy/jazzy_markdown'

module Jazzy
class Doc < Mustache
self.template_name = 'doc'

def date
# Fake date is used to keep integration tests consistent
ENV['JAZZY_FAKE_DATE'] || DateTime.now.strftime('%Y-%m-%d')
end

def year
# Fake date is used to keep integration tests consistent
if ENV['JAZZY_FAKE_DATE']
ENV['JAZZY_FAKE_DATE'][0..3]
else
DateTime.now.strftime('%Y')
end
def copyright
config = Config.instance
copyright = config.copyright || (
# Fake date is used to keep integration tests consistent
date = ENV['JAZZY_FAKE_DATE'] || DateTime.now.strftime('%Y-%m-%d')
year = date[0..3]
"&copy; #{year} [#{config.author_name}](#{config.author_url}). " \
"All rights reserved. (Last updated: #{date})"
)
Jazzy.copyright_markdown.render(copyright).chomp
end

def jazzy_version
Expand Down
2 changes: 0 additions & 2 deletions lib/jazzy/doc_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def self.document_index(source_module, path_to_root)
doc[:structure] = source_module.doc_structure
doc[:module_name] = source_module.name
doc[:author_name] = source_module.author_name
doc[:author_website] = source_module.author_url.to_s
doc[:github_url] = source_module.github_url.to_s
doc[:dash_url] = source_module.dash_url
doc[:path_to_root] = path_to_root
Expand Down Expand Up @@ -288,7 +287,6 @@ def self.document(source_module, doc_model, path_to_root)
doc[:tasks] = render_tasks(source_module, doc_model.children)
doc[:module_name] = source_module.name
doc[:author_name] = source_module.author_name
doc[:author_website] = source_module.author_url.to_s
doc[:github_url] = source_module.github_url.to_s
doc[:dash_url] = source_module.dash_url
doc[:path_to_root] = path_to_root
Expand Down
16 changes: 15 additions & 1 deletion lib/jazzy/jazzy_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ def header(text, header_level)
end

def self.markdown
@markdown ||= Redcarpet::Markdown.new(JazzyHTML, JazzyHTML::OPTIONS)
@markdown ||= Redcarpet::Markdown.new(JazzyHTML, JazzyHTML::OPTIONS)
end

class JazzyCopyright < Redcarpet::Render::HTML
def link(link, _title, content)
%(<a class="link" href="#{link}" target="_blank" \
rel="external">#{content}</a>)
end
end

def self.copyright_markdown
@copyright_markdown ||= Redcarpet::Markdown.new(
JazzyCopyright,
JazzyHTML::OPTIONS,
)
end
end
2 changes: 1 addition & 1 deletion lib/jazzy/templates/footer.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section id="footer">
<p>&copy; {{year}} <a class="link" href="{{author_website}}" target="_blank" rel="external">{{author_name}}</a>. All rights reserved. (Last updated: {{date}})</p>
{{{copyright}}}
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v{{jazzy_version}}</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>

0 comments on commit 8c89cd9

Please sign in to comment.