-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
133 lines (102 loc) · 2.53 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
require_relative "lib/all"
class Redcarpet::Markdown
attr_accessor :issue_object
def new_render(src)
@renderer.issue_object = issue_object
render(src)
end
end
class HTMLwithPygments < Redcarpet::Render::HTML
def block_code(code, language)
Pygments.highlight(code, lexer: language)
end
end
class OldIssue
attr_reader :id
def initialize(id, clean = false)
@id = id
@clean = clean
end
def url
'https://github.com/SphereSoftware/weekly'
end
def name
'Sphere Rebel Weekly'
end
def content
@issue_content ||= begin
markdown.render(source)
end
end
def issue_file_path
File.dirname(__FILE__) + "/#{Date.today.year}/issue-#{"%03d" % id}/README.md"
end
def index
index_template.result(binding)
end
def email
email_template.result(binding)
end
def template
issue_template.result(binding)
end
def text
source
end
def dir_path
"#{Date.today.year}/issue-%03d" % id
end
private
def source
File.open(issue_file_path).readlines.join
end
def index_template
ERB.new(File.open(File.dirname(__FILE__) + "/issue.html.erb").readlines.join)
end
def email_template
if clean?
ERB.new("<%= content %>")
else
ERB.new(File.open(File.dirname(__FILE__) + "/email.html.erb").readlines.join)
end
end
def issue_template
ERB.new(File.open(File.dirname(__FILE__) + "/issue-template.md").readlines.join)
end
def markdown
@md ||= Redcarpet::Markdown.new(HTMLwithPygments, fenced_code_blocks: true)
end
def clean?
@clean
end
end
def current_issue
Dir["#{Date.today.year}/issue*"].last.split('-').last.to_i
end
task :new => :dotenv do
next_issue_number = current_issue + 1
issue = OldIssue.new(next_issue_number, true)
# create directory is needed
unless File.directory?(issue.dir_path)
FileUtils.mkdir_p(issue.dir_path)
end
# write a file
File.open(issue.issue_file_path, 'w') do |file|
file.write(issue.template)
end
# link the issue
current_file = File.dirname(__FILE__) + '/current.md'
FileUtils.rm_f(current_file) if File.exist?(current_file) || File.symlink?(current_file)
FileUtils.symlink(issue.issue_file_path, current_file)
# puts issue.default_md
puts current_issue, 'created 🎉🍻'
end
task :show => :dotenv do
issue = OldIssue.new(current_issue, true)
File.open('/tmp/rebel-weekly.html', 'w') { |file| file.write(issue.email) }
sh "open /tmp/rebel-weekly.html"
end
task :build => :dotenv do
Weekly.new(current_issue).build
end
task default: %w[show]