-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
147 lines (119 loc) · 3.72 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require 'yaml'
require 'erb'
require 'pathname'
require 'rake/clean'
PROJECT_NAME = Pathname.new(Dir.pwd).basename.freeze
USERNAME = `whoami`.strip.freeze
SLIDEMAKER_PATH = Pathname.new('../../slidemaker').freeze
PUBLIC_PATH = Pathname.new("../slides/#{PROJECT_NAME}").freeze
task default: :work
desc 'Launch the project in Google Chrome, Sublime Text and Guard'
task work: [:sublime, :chrome, :guard]
desc 'Launch the slides in Google Chrome in print-pdf mode'
task pdf: :host do |t|
sh "open #{url}?print-pdf"
end
namespace :static do
desc 'Extract static assets into a public project'
task extract: [PUBLIC_PATH, 'config.yml'] do
if PUBLIC_PATH.empty?
title = YAML.load_file('config.yml')['title']
unknown_file = PUBLIC_PATH.join('slides')
cp_r 'slides/.', PUBLIC_PATH
rm unknown_file if unknown_file.exist?
render_erb(SLIDEMAKER_PATH.join('erb', 'README.md.erb'), PUBLIC_PATH.join('README.md'), title)
open(PUBLIC_PATH.parent.join('README.md'), 'a') do |readme|
readme << "* [#{title}](https://rastamhadi.github.io/slides/#{PROJECT_NAME})\n"
end
end
end
CLOBBER.include(PUBLIC_PATH)
desc 'Launch extracted static assets project in gitsh'
task gitsh: PUBLIC_PATH do
cd PUBLIC_PATH do
sh 'gitsh'
end
end
desc 'Launch extracted static assets project in Sublime Text'
task sublime: PUBLIC_PATH do
cd PUBLIC_PATH do
sh 'sublime .'
end
end
end
namespace :host do
desc 'Host the slides locally and print the URL'
task url: :host do
puts url
end
end
desc 'Host the slides locally'
task host: "/Users/#{USERNAME}/Sites/#{PROJECT_NAME}"
desc 'Launch the slides in Google Chrome'
task chrome: 'slides/index.html' do |t|
sh "open #{t.source}"
end
desc 'Guard the project'
task guard: :init do
sh 'rbenv exec bundle exec guard'
end
desc 'Launch gitsh'
task gitsh: '.git/refs/remotes' do
sh 'gitsh'
end
desc 'Launch the project in Sublime Text'
task sublime: :init do
sh 'sublime .'
end
desc 'Generate a new reveal-ck project'
task init: ['Gemfile.lock', 'Guardfile', 'slides/index.html']
file '.git/refs/remotes' => '.git' do
puts 'What is your Bitbucket username?'
username = $stdin.gets.chomp
sh "git remote add origin git@bitbucket.org:#{username}/#{PROJECT_NAME}.git"
end
file '.git' do
sh 'git init'
end
SYM_LINK_PATH = "/Users/#{USERNAME}/Sites/#{PROJECT_NAME}".freeze
file SYM_LINK_PATH => 'slides/index.html' do |t|
sh "ln -s #{Pathname.new(t.source).parent.realpath} #{t.name}"
end
CLOBBER.include(SYM_LINK_PATH)
file 'slides/index.html' => 'slides.md' do
sh 'reveal-ck generate'
end
CLOBBER.include('slides')
file 'slides.md' => [SLIDEMAKER_PATH.join('erb', 'slides.md.erb'), 'config.yml'] do |t|
title = YAML.load_file(t.sources.last)['title']
render_erb(t.source, t.name, title)
end
CLOBBER.include('slides.md')
file 'config.yml' => SLIDEMAKER_PATH.join('erb', 'config.yml.erb') do |t|
puts 'What is the title of your slides?'
title = $stdin.gets.chomp
render_erb(t.source, t.name, title)
end
CLOBBER.include('config.yml')
file 'Gemfile.lock' => ['Gemfile', '.ruby-version'] do
sh 'rbenv exec bundle install'
end
CLOBBER.include('Gemfile.lock')
Rake::FileList.new(SLIDEMAKER_PATH.join('templates', '*')).each do |template|
file template.pathmap('%f') => template do |t|
cp t.source, t.name
end
CLOBBER.include(template.pathmap('%f'))
end
file '.ruby-version' do
sh "rbenv versions | tail -n1 | awk '{$1=$1};1' > .ruby-version"
end
CLOBBER.include('.ruby-version')
directory PUBLIC_PATH
def url
"http://#{`ipconfig getifaddr en0`.strip}/~#{USERNAME}/#{PROJECT_NAME}"
end
def render_erb(erb_path, out_path, title)
erb = ERB.new(File.read(erb_path)).result(binding)
open(out_path, "w+") { |f| f.write(erb) }
end