blog-generator 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/lib/blog-generator/post.rb +20 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd69adf8a5bac92678f54a4deb3f5ce782072e6d
4
- data.tar.gz: 0b41a6c428acb27b37d78269d505410f3ba9ba5b
3
+ metadata.gz: 45917f716b8adb235bd224c77de901117a168a69
4
+ data.tar.gz: df11142024e55d3e0e8874fadac2ef5111e7236f
5
5
  SHA512:
6
- metadata.gz: 258e376eeda8f4fd2fc624992553ef6c19f3174b9a14820fa2204917df66cd0fe7963a845efa9a7eb08f58dbc13694c9e52334cdbd31ee1080f872e42e7d7c45
7
- data.tar.gz: e8dcb5729b3036cef81c9a98520574155d2ce9b3d3fafeca9ae799a27bc4dc81e378eaa7d4b71985f9f17f963195eea76ddfda7f5882d859f4abf80e7a68bb87
6
+ metadata.gz: 05c7bf751d666aadd87c34f28ac9b028b4538b1fdbe13911e0e6eeb7907374c5f323c2b3b20b91f5ee15f6bbf1c7e67fddaa36478e42cb9dccc73edc8f698668
7
+ data.tar.gz: db8081ab2a337d2a8659570f069bac6bf1fe9e835d9c55a95bbfc53b5d369d3bc39e0211da40d65604a7878fb01d67daa6246a606486c88ae787268f17fe80c0
data/README.md CHANGED
@@ -44,6 +44,10 @@ tags: ['Hello world', 'Test']
44
44
  <p>
45
45
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta quibusdam necessitatibus tempore ullam incidunt amet omnis, veritatis dicta quisquam accusamus at provident vel facere corporis sed fugiat cumque. Consequuntur, necessitatibus!
46
46
  </p>
47
+
48
+ <!-- This assumes assets/hello-world/hello-kitty.png -->
49
+ <img src="/assets/hello-world/hello-kitty.png" />
50
+ <caption>Hello kitty!</caption>
47
51
  ```
48
52
 
49
53
  ## Assumptions
@@ -73,10 +73,29 @@ module BlogGenerator
73
73
  @body ||= begin
74
74
  document = nokogiri_raw_document.dup
75
75
  document.css('#excerpt').remove
76
+ document.css('img[src^="/assets/"]').each do |img|
77
+ absolute_url = img.attribute('src').value
78
+ asset_path = "..#{absolute_url}" # This is extremely shakey, it depends on us being in api.botanicus.me.
79
+ if File.exists?(asset_path)
80
+ img['src'] = image_binary_data(asset_path)
81
+ else
82
+ raise "Asset #{asset_path} doesn't exist."
83
+ end
84
+ end
76
85
  document.css('body').inner_html.strip
77
86
  end
78
87
  end
79
88
 
89
+ def image_binary_data(asset_path)
90
+ require 'base64'
91
+
92
+ extension = File.extname(asset_path)[1..-1]
93
+ binary_data = File.read(asset_path)
94
+ encoded_data = Base64.encode64(binary_data)
95
+
96
+ "data:image/#{extension};base64,#{encoded_data}"
97
+ end
98
+
80
99
  def excerpt
81
100
  @excerpt ||= begin
82
101
  document = nokogiri_raw_document.dup
@@ -85,7 +104,7 @@ module BlogGenerator
85
104
  end
86
105
 
87
106
  def as_json
88
- @metadata.merge(body: body).tap do |metadata|
107
+ @metadata.merge(body: self.body).tap do |metadata|
89
108
  metadata[:published_at] && metadata[:published_at] = DateTime.parse(metadata[:published_at])
90
109
  metadata[:updated_at] && metadata[:updated_at] = DateTime.parse(metadata[:updated_at])
91
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blog-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James C Russell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri