-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap google document in
Document
class
This avoids having to have decoration logic (like formatting the date) in multiple places.
- Loading branch information
1 parent
2cbc315
commit d9d4151
Showing
8 changed files
with
162 additions
and
53 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,40 @@ | ||
class Document | ||
def initialize(google_document) | ||
@google_document = google_document | ||
end | ||
|
||
def id | ||
@google_document.id | ||
end | ||
|
||
def title | ||
@google_document.title | ||
end | ||
|
||
def modified_time | ||
@google_document.modified_time | ||
end | ||
|
||
def modified_time_display | ||
modified_time.strftime('%d %b %Y') | ||
end | ||
|
||
def last_author_name | ||
@google_document.last_modifying_user.display_name | ||
end | ||
|
||
def html_body | ||
article_json.to_html | ||
end | ||
|
||
private | ||
|
||
def article_json | ||
@article_json ||= | ||
ArticleJSON::Article.from_google_doc_html(google_doc_html) | ||
end | ||
|
||
def google_doc_html | ||
@google_document.export_as_string('html') | ||
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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<h1><%= doc.title %></h1> | ||
<div class="meta-info"> | ||
<cite><%= doc.last_modifying_user.display_name %></cite> | ||
<cite><%= doc.last_author_name %></cite> | ||
// | ||
<time><%= doc.modified_time.strftime('%d %b %Y') %></time> | ||
<time><%= doc.modified_time_display %></time> | ||
</div> | ||
<article> | ||
<%= ArticleJSON::Article.from_google_doc_html(doc.export_as_string('html')).to_html %> | ||
<%= doc.html_body %> | ||
</article> |
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,52 @@ | ||
require 'spec_helper' | ||
require_relative '../app/document' | ||
|
||
describe Document do | ||
let(:user_double) { double 'user', display_name: 'Us Er' } | ||
let(:modified_time) { DateTime.parse('2017-11-24T12:39:41') } | ||
let(:google_doc_double) do | ||
double 'document', | ||
id: 'd0c_1d', | ||
modified_time: modified_time, | ||
title: 'My first document', | ||
last_modifying_user: user_double | ||
end | ||
let(:instance) { described_class.new(google_doc_double) } | ||
let(:html) { File.read('spec/fixtures/google_doc.html') } | ||
|
||
before do | ||
allow(google_doc_double) | ||
.to receive(:export_as_string).with('html').and_return(html) | ||
end | ||
|
||
describe '#id' do | ||
subject { instance.id } | ||
it { should eq google_doc_double.id } | ||
end | ||
|
||
describe '#title' do | ||
subject { instance.title } | ||
it { should eq google_doc_double.title } | ||
end | ||
|
||
describe '#modified_time' do | ||
subject { instance.modified_time } | ||
it { should eq google_doc_double.modified_time } | ||
end | ||
|
||
describe '#modified_time_display' do | ||
subject { instance.modified_time_display } | ||
it { should eq '24 Nov 2017' } | ||
end | ||
|
||
describe '#last_author_name' do | ||
subject { instance.last_author_name } | ||
it { should eq user_double.display_name } | ||
end | ||
|
||
describe '#html_body' do | ||
subject { instance.html_body } | ||
it { should be_a String } | ||
it { should include "It's nice when it works!" } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<html> | ||
<head> | ||
<meta content="text/html; charset=UTF-8" http-equiv="content-type"> | ||
<style type="text/css"></style> | ||
</head> | ||
<body style="background-color:#ffffff;padding:72pt 72pt 72pt 72pt;max-width:468pt"> | ||
<h1 id="h.rdp4m3ei7nk6" style="padding-top:20pt;margin:0;color:#000000;padding-left:0;font-size:20pt;padding-bottom:6pt;line-height:1.15;page-break-after:avoid;font-family:"Arial";orphans:2;widows:2;text-align:left;padding-right:0"> | ||
<span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:20pt;font-family:"Arial";font-style:normal">Simple article</span> | ||
</h1> | ||
<p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:"Arial";line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"> | ||
<span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:"Arial";font-style:normal"></span> | ||
</p> | ||
<p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:"Arial";line-height:1.15;orphans:2;widows:2;text-align:left"> | ||
<span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:"Arial";font-style:normal">It's nice when it works!</span> | ||
</p> | ||
<p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:"Arial";line-height:1.15;orphans:2;widows:2;height:11pt;text-align:left"> | ||
<span style="color:#000000;font-weight:400;text-decoration:none;vertical-align:baseline;font-size:11pt;font-family:"Arial";font-style:normal"></span> | ||
</p> | ||
</body> | ||
</html> |
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