@@ -100,32 +100,6 @@ impl MDBook {
100
100
output ! ( "{:?} created" , self . config. get_root( ) ) ;
101
101
}
102
102
103
- {
104
- let root = self . config . get_root ( ) ;
105
- let gitignore = root. join ( ".gitignore" ) ;
106
-
107
- if !gitignore. exists ( ) {
108
-
109
- // Gitignore does not exist, create it
110
-
111
- debug ! ( "[*]: {:?} does not exist, trying to create .gitignore" , root. join( ".gitignore" ) ) ;
112
-
113
- let dest = self . config . get_dest ( ) ;
114
- // `relative_from` is marked as unstable
115
- // http://doc.rust-lang.org/std/path/struct.PathBuf.html#method.relative_from
116
- let dest = dest. relative_from ( root)
117
- . expect ( "Destination path does not start with root path." ) ;
118
- let dest = dest. to_str ( )
119
- . expect ( "No destination path found." ) ;
120
-
121
- let mut f = try!( File :: create ( & root. join ( ".gitignore" ) ) ) ;
122
-
123
- debug ! ( "[*]: Writing to .gitignore" ) ;
124
-
125
- try!( writeln ! ( f, "{}" , dest) ) ;
126
- }
127
- }
128
-
129
103
{
130
104
let dest = self . config . get_dest ( ) ;
131
105
let src = self . config . get_src ( ) ;
@@ -186,12 +160,37 @@ impl MDBook {
186
160
Ok ( ( ) )
187
161
}
188
162
163
+ pub fn create_gitignore ( & self ) {
164
+ let gitignore = self . get_gitignore ( ) ;
165
+
166
+ if !gitignore. exists ( ) {
167
+ // Gitignore does not exist, create it
168
+
169
+ debug ! ( "[*]: {:?} does not exist, trying to create .gitignore" , gitignore) ;
170
+
171
+ let mut f = File :: create ( & gitignore)
172
+ . expect ( "Could not create file." ) ;
173
+
174
+ debug ! ( "[*]: Writing to .gitignore" ) ;
175
+
176
+ writeln ! ( f, "# Ignore everything within this folder" )
177
+ . expect ( "Could not write to file." ) ;
178
+ writeln ! ( f, "*" )
179
+ . expect ( "Could not write to file." ) ;
180
+ writeln ! ( f, "" )
181
+ . expect ( "Could not write to file." ) ;
182
+ writeln ! ( f, "# Except this file" )
183
+ . expect ( "Could not write to file." ) ;
184
+ writeln ! ( f, "!.gitignore" )
185
+ . expect ( "Could not write to file." ) ;
186
+ }
187
+ }
188
+
189
189
/// The `build()` method is the one where everything happens. First it parses `SUMMARY.md` to
190
190
/// construct the book's structure in the form of a `Vec<BookItem>` and then calls `render()`
191
191
/// method of the current renderer.
192
192
///
193
193
/// It is the renderer who generates all the output files.
194
-
195
194
pub fn build ( & mut self ) -> Result < ( ) , Box < Error > > {
196
195
debug ! ( "[fn]: build" ) ;
197
196
@@ -206,6 +205,10 @@ impl MDBook {
206
205
}
207
206
208
207
208
+ pub fn get_gitignore ( & self ) -> PathBuf {
209
+ self . config . get_dest ( ) . join ( ".gitignore" )
210
+ }
211
+
209
212
pub fn copy_theme ( & self ) -> Result < ( ) , Box < Error > > {
210
213
debug ! ( "[fn]: copy_theme" ) ;
211
214
@@ -323,6 +326,10 @@ impl MDBook {
323
326
Ok ( ( ) )
324
327
}
325
328
329
+ pub fn get_root ( & self ) -> & Path {
330
+ self . config . get_root ( )
331
+ }
332
+
326
333
pub fn set_dest ( mut self , dest : & Path ) -> Self {
327
334
328
335
// Handle absolute and relative paths
0 commit comments