-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use templates to render rich text pages (#512)
- Loading branch information
Showing
3 changed files
with
99 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module ExportHelper | ||
def self.sanitize_filename(filename) | ||
filename.gsub(/[\x00\/\\:\*\?\"<>\|]/, "_").strip | ||
end | ||
def self.get_path(document_id, current_depth) | ||
# get a relative URL to a document by id, taking into account the current location | ||
document = Document.find(document_id) | ||
filename = self.sanitize_filename(document.title).parameterize | ||
path_segments = ["#{filename}.html"] | ||
while document[:parent_type] != "Project" | ||
# back out from the target document until we hit the project root | ||
document = document.parent | ||
path_segments.unshift(self.sanitize_filename(document[:title])) | ||
end | ||
to_project_root = current_depth > 0 ? Array.new(current_depth, "..").join("/") + "/" : "" | ||
path = to_project_root + path_segments.join("/") | ||
return path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<style type="text/css"> | ||
body { | ||
font-family: Roboto, sans-serif; | ||
} | ||
li:target, | ||
a.dm-highlight:target { | ||
box-shadow: 0 0px 8px blue, 0 0px 8px blue, 0 0px 8px blue; | ||
} | ||
<% @highlights.each do |uuid, hl| %> | ||
a[class*="<%= uuid %>"] { | ||
color: black; | ||
background-color: <%= hl.color %>; | ||
} | ||
<% end %> | ||
</style> | ||
<body> | ||
<main> | ||
<% @images.each do |image| %> | ||
<%= image %> | ||
<br /> | ||
<% end %> | ||
<%= @content %> | ||
</main> | ||
<% if @highlights %> | ||
<footer> | ||
<ol> | ||
<% @highlights.each do |uuid, hl| %> | ||
<li id="<%= uuid %>"> | ||
<a href="#highlight-<%= uuid %>" class="<%= uuid %>"><%= hl.title || hl.excerpt %></a> | ||
<% if hl.links_to %> | ||
<ol> | ||
<% hl.links_to.each do |link| %> | ||
<li> | ||
<% if link[:document_id].present? %> | ||
<a href="<%= ExportHelper.get_path(link[:document_id], @depth) %>"> | ||
<%= link[:title] %> | ||
</a> | ||
<% else %> | ||
<%= link[:title] %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ol> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ol> | ||
</footer> | ||
<% end %> | ||
</body> |