Skip to content

Commit 6dbaa31

Browse files
committedJun 13, 2019
Add image generation for blog
1 parent 1eba154 commit 6dbaa31

9 files changed

+117
-31
lines changed
 
File renamed without changes.

‎Gemfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
source 'https://rubygems.org' do
2+
gem 'colorize'
23
gem 'csv2md'
3-
end
4+
gem 'commonmarker'
5+
gem 'wkhtmltoimage-binary'
6+
gem 'imgkit'
7+
end

‎Gemfile.lock

+14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
colorize (0.8.1)
5+
commonmarker (0.20.1)
6+
ruby-enum (~> 0.5)
7+
concurrent-ruby (1.1.5)
48
csv2md (1.1.3)
9+
i18n (1.6.0)
10+
concurrent-ruby (~> 1.0)
11+
imgkit (1.6.2)
12+
ruby-enum (0.7.2)
13+
i18n
14+
wkhtmltoimage-binary (0.12.5)
515

616
PLATFORMS
717
ruby
818

919
DEPENDENCIES
20+
colorize!
21+
commonmarker!
1022
csv2md!
23+
imgkit!
24+
wkhtmltoimage-binary!
1125

1226
BUNDLED WITH
1327
2.0.1

‎README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This is a Cheatsheet for [RxSwift](https://github.com/ReactiveX/RxSwift) develop
33

44
It's based on the following blog post: [https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b](https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b)
55

6-
## [Basics](Data/Basics.csv)
6+
## [Basics](Data/basics.csv)
77

88
| | RxSwift | Combine |
99
|-----------------------|----------------------------------|--------------------------------------------|
@@ -15,7 +15,7 @@ It's based on the following blog post: [https://medium.com/gett-engineering/rxsw
1515
| UI Bindings | RxCocoa | SwiftUI ² |
1616

1717

18-
## [Core Components](Data/CoreComponents.csv)
18+
## [Core Components](Data/core_components.csv)
1919

2020
| RxSwift | Combine | Notes |
2121
|---------------------------|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
@@ -31,7 +31,7 @@ It's based on the following blog post: [https://medium.com/gett-engineering/rxsw
3131
| SchedulerType | Scheduler | |
3232

3333

34-
## [Operators](Data/Operators.csv)
34+
## [Operators](Data/operators.csv)
3535

3636
| RxSwift | Combine | Notes |
3737
|-------------------------------|---------------------------------------|----------------------------------------------------------------------------------------------------------|
@@ -79,4 +79,6 @@ It's based on the following blog post: [https://medium.com/gett-engineering/rxsw
7979

8080

8181
# Contributing
82-
Add any data/operators to the appropriate CSV files in the **Data** folder, run `genreadme.rb` and commit the changes. Then, submit a Pull Request
82+
Add any data/operators to the appropriate CSV files in the **Data** folder, run `bundle install` and `generate.rb`.
83+
84+
Finally, commit the changes and submit a Pull Request.

‎Resources/basics.jpg

45.7 KB
Loading

‎Resources/core_components.jpg

72.4 KB
Loading

‎Resources/operators.jpg

194 KB
Loading

‎generate.rb

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env ruby
2+
3+
system("csv2md > /dev/null 2>&1")
4+
error("csv2md is not intalled, Please run `bundle install` first") unless $?.exitstatus == 0
5+
6+
require 'commonmarker'
7+
require 'imgkit'
8+
require 'colorize'
9+
10+
docs = {
11+
"basics.csv" => "Basics",
12+
"core_components.csv" => "Core Components",
13+
"operators.csv" => "Operators"
14+
}
15+
16+
output = "# RxSwift to Combine Cheatsheet\n" +
17+
"This is a Cheatsheet for [RxSwift](https://github.com/ReactiveX/RxSwift) developers interested in Apple's new [Combine](https://developer.apple.com/documentation/combine) framework.\n\n" +
18+
"It's based on the following blog post: [https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b](https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b)\n\n"
19+
20+
puts "Rebuilding README.md ...".purple
21+
22+
docs.each { |file, title|
23+
## Generate markdown for the specific section
24+
output += "## [#{title}](Data/#{file})\n\n"
25+
table = `csv2md Data/#{file}`
26+
output += table
27+
output += "\n\n"
28+
29+
image_file = file.sub(".csv", ".jpg")
30+
31+
puts "Generating image: #{image_file}".light_blue
32+
33+
## Convert markdown to HTML
34+
tableHTML = CommonMarker.render_html(table, :DEFAULT, %i[table])
35+
36+
html = <<-HTML
37+
<!DOCTYPE html>
38+
<html lang="en">
39+
<head>
40+
<meta charset="utf-8" />
41+
<title>HTML5 Doctor | Element Index</title>
42+
<style type="text/css">
43+
* {
44+
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
45+
font-size: 16px;
46+
line-height: 1.5;
47+
}
48+
49+
table {
50+
width: 100%;
51+
border-collapse: collapse;
52+
border-spacing: 0;
53+
}
54+
55+
tr:nth-child(2n) {
56+
background-color: #f6f8fa;
57+
}
58+
59+
tr {
60+
background-color: #fff;
61+
}
62+
63+
td {
64+
padding: 6px 13px;
65+
border: 1px solid #dfe2e5;
66+
display: table-cell;
67+
}
68+
69+
th {
70+
border: 1px solid #dfe2e5;
71+
padding: 6px 13px;
72+
font-weight: bold;
73+
}
74+
</style>
75+
</head>
76+
<body>
77+
#{tableHTML}</body>
78+
</html>
79+
HTML
80+
81+
## Convert HTML to Image 🤯
82+
kit = IMGKit.new(html, :quality => 85)
83+
file = kit.to_file("Resources/#{image_file}")
84+
}
85+
86+
output += "# Contributing\n"
87+
output += "Add any data/operators to the appropriate CSV files in the **Data** folder, run `bundle install` and `generate.rb`.\n\nFinally, commit the changes and submit a Pull Request."
88+
89+
puts "Writing README.md ...".purple
90+
File.write('README.md', output)
91+
92+
puts "🎉 All done! 🎉".green

‎genreadme.rb

-26
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.