Skip to content
This repository
Browse code

Remove old Rakefile

  • Loading branch information...
commit 702f533536f2685c6857be3d1b2e60ab712a5903 1 parent 9237746
Premasagar Rose authored September 26, 2012

Showing 1 changed file with 0 additions and 272 deletions. Show diff stats Hide diff stats

  1. 272  Rakefile
272  Rakefile
... ...
@@ -1,272 +0,0 @@
1  
-require 'fileutils'
2  
-require 'json'
3  
-
4  
-
5  
-### Configuration variables
6  
-$docs_dir           = "docs"
7  
-$posts_dir          = "_posts"
8  
-site_branch         = "gh-pages"
9  
-dharmafly_docs_repo = "git@github.com:dharmafly/dharmafly-docs.git"
10  
-$default_category   = "about"
11  
-
12  
-
13  
-### Tasks
14  
-
15  
-
16  
-desc "Initializes dharmafly-docs if #{site_branch} does not exist, otherwise copies posts to #{site_branch}"
17  
-task :build do
18  
-  raise "You're already in the #{site_branch} branch!" if Git.active_branch?(site_branch)
19  
-  raise "Your project does not have a '#{$docs_dir}' directory!" unless File.directory?($docs_dir)
20  
-
21  
-  # Cache all of the docs files
22  
-  cached_docs = cache_docs($docs_dir)
23  
-  
24  
-  # Checkout to site branch
25  
-  if Git.branch_exists?(site_branch)
26  
-    clean_install = false
27  
-    sh("git checkout #{site_branch}")
28  
-  else
29  
-    clean_install = true
30  
-    sh("git checkout --orphan #{site_branch}")
31  
-
32  
-    # Remove existing files
33  
-    sh("git rm -rf .")
34  
-
35  
-    # Add the dharmafly-docs repo
36  
-    sh("git remote add dharmafly-docs #{dharmafly_docs_repo}") unless Git.remote_exists?("dharmafly-docs")
37  
-
38  
-    # Pull the docs repo
39  
-    sh("git pull dharmafly-docs master")
40  
-
41  
-    # Remove the dharmafly-docs repo
42  
-    sh("git remote rm dharmafly-docs") if Git.remote_exists?("dharmafly-docs")
43  
-  end
44  
-
45  
-  # Delete the posts directory if it exists
46  
-  sh("git rm -rf #{$posts_dir}") if File.directory?($posts_dir)
47  
-
48  
-  # Recreate the posts directory
49  
-  Dir.mkdir($posts_dir)
50  
-
51  
-  # Create a post for each doc
52  
-  create_posts(cached_docs, $posts_dir)
53  
-
54  
-  # Add & Commit the posts to the repo
55  
-  sh("git add .")
56  
-
57  
-  if clean_install
58  
-    sh('git commit . -m "Create project documentation with dharmafly docs"')
59  
-  else
60  
-    sh('git commit . -m "Update project documentation with dharmafly docs"') rescue puts "commit aborted"
61  
-  end
62  
-
63  
-  puts "\nDocs generated successfully! " + "Don't forget to update your _config.yml".bright()
64  
-  puts "\nTo push the changes, type:"
65  
-  puts "git push origin #{site_branch}"
66  
-
67  
-  # Notify user of active branch
68  
-  puts "\nActive Branch: ".bold_green() + Git.active_branch
69  
-end
70  
-
71  
-desc "Start a local development server to test the site. (Requires Jekyll)"
72  
-task :server do 
73  
-  unless jekyll_is_installed?
74  
-    raise "Jekyll is not installed. To install Jekyll, run:\nsudo gem install jekyll"
75  
-  end
76  
-  
77  
-  # Switch to the site branch if not there already
78  
-  sh("git checkout #{site_branch}") unless Git.active_branch?(site_branch)
79  
-
80  
-  # Start the Jekyll server
81  
-  sh("jekyll --server")
82  
-
83  
-  # Notify user of active branch
84  
-  puts "\nActive Branch: ".bold_green() + Git.active_branch
85  
-end
86  
-
87  
-desc "Pulls to latest version of dharmafly-docs to your #{site_branch} branch."
88  
-task :upgrade do
89  
-  raise "Your project does not have a #{site_branch} branch!" unless Git.branch_exists?(site_branch)
90  
-
91  
-  # Switch to the site branch if not there already
92  
-  sh("git checkout #{site_branch}") unless Git.active_branch?(site_branch)
93  
-
94  
-  # Add the dharmafly-docs repo
95  
-  sh("git remote add dharmafly-docs #{dharmafly_docs_repo}") unless Git.remote_exists?("dharmafly-docs")
96  
-
97  
-  # Pull the docs repo
98  
-  sh("git pull dharmafly-docs master")
99  
-
100  
-  # Remove the dharmafly-docs repo
101  
-  sh("git remote rm dharmafly-docs") if Git.remote_exists?("dharmafly-docs")
102  
-
103  
-  # Notify user of active branch
104  
-  puts "\nActive Branch: ".bold_green() + Git.active_branch
105  
-end
106  
-
107  
-#namespace :post do
108  
-
109  
-#  desc "Create a new post"
110  
-#  task :new, :title do |t, args|
111  
-#    raise "You're not in the #{site_branch} branch!" if active_branch != site_branch
112  
-#    puts args.title
113  
-#  end
114  
-
115  
-#end
116  
-
117  
-
118  
-
119  
-
120  
-### methods
121  
-
122  
-
123  
-
124  
-
125  
-# Converts the filename of a doc to the Jekyll post format
126  
-def postify(filename)
127  
-  number = ""
128  
-  post_title_start = 0
129  
-
130  
-  # get the number out of the filename string
131  
-  filename.split("").each_with_index do |c, i|
132  
-    post_title_start = i + 1
133  
-    break if c == " " or c == "-"
134  
-    next if not c.is_numeric?
135  
-    number += c
136  
-  end
137  
-
138  
-  # used to determine if a 1 has been prepended yet
139  
-  prepend_number = ""
140  
-
141  
-  # add preceding 1 & zeros if number is less then 4 digits
142  
-  until  prepend_number.length + number.length >= 4 do
143  
-    if prepend_number === ""
144  
-      prepend_number = "2" + prepend_number
145  
-    else
146  
-      prepend_number = "0" + prepend_number
147  
-    end
148  
-  end
149  
-
150  
-  # add rest of fake date
151  
-  post_name = prepend_number.reverse() + number + "-01-01-" 
152  
-
153  
-  # built post title
154  
-  post_title = filename[post_title_start..-1]
155  
-  post_title = post_title.downcase()
156  
-  post_title = post_title.gsub(" ", "-")
157  
-
158  
-  # add it all together and return it
159  
-  post_name += post_title
160  
-end
161  
-
162  
-# Add front matter if it doesn't already exist
163  
-def add_front_matter(file_contents)
164  
-  if has_front_matter?(file_contents)
165  
-    return file_contents
166  
-  else
167  
-    return "---\ncategory: #{$default_category}\n---\n" + file_contents
168  
-  end
169  
-end
170  
-
171  
-# Returns true if the file contains front matter
172  
-def has_front_matter?(file_contents)
173  
-  return file_contents[0..3] === "---\n"
174  
-end
175  
-
176  
-# Returns true if Jekyll is installed on this system
177  
-def jekyll_is_installed?
178  
-  begin
179  
-    `jekyll`
180  
-  rescue
181  
-    return false
182  
-  else
183  
-    return true
184  
-  end
185  
-end
186  
-
187  
-module Git
188  
-
189  
-  # Returns the remotes in the repo
190  
-  def Git.remote
191  
-    `git remote`.split(/\r?\n/)
192  
-  end
193  
-
194  
-  # Returns true if parameterized remote exists
195  
-  def Git.remote_exists?(remote)
196  
-    Git.remote.include?(remote)
197  
-  end
198  
-
199  
-  # Returns the branches of the repo
200  
-  def Git.branch
201  
-    `git branch`.split(/\r?\n/)
202  
-  end
203  
-
204  
-  # Returns true if the parameterized branch exists
205  
-  def Git.branch_exists?(branch_name)
206  
-    Git.branch.include?("  #{branch_name}")
207  
-  end
208  
-
209  
-  # Returns the currently active branch
210  
-  def Git.active_branch
211  
-    Git.branch.each do |branch|
212  
-      return branch[2..-1] if branch[0] === "*"
213  
-    end
214  
-  end
215  
-
216  
-  # Returns true if the parameterized branch is the one 
217  
-  # that is active at the moment
218  
-  def Git.active_branch?(branch)
219  
-    Git.active_branch === branch
220  
-  end
221  
-
222  
-end
223  
-
224  
-# Create a hash out of each doc in the docs_dir
225  
-def cache_docs (docs_dir)
226  
-  rtn = Hash.new()
227  
-
228  
-  Dir.foreach(docs_dir) do |item|
229  
-    next if item[0] === "." or File.directory?(item)
230  
-    rtn[item] = File.read("#{docs_dir}/#{item}")
231  
-  end
232  
-
233  
-  return rtn
234  
-end
235  
-
236  
-# Create posts for each cached doc
237  
-def create_posts (cached_docs, posts_dir)
238  
-  cached_docs.each do |old_name, contents|
239  
-    new_name = postify(old_name)
240  
-    puts "write '#{posts_dir}/#{new_name}'"
241  
-    file = File.new("#{posts_dir}/#{new_name}", "w")
242  
-    file << add_front_matter(contents)
243  
-    file.close()
244  
-  end
245  
-end
246  
-
247  
-
248  
-### helper functions
249  
-
250  
-
251  
-class String
252  
-  def is_numeric?
253  
-    true if Float(self) rescue false
254  
-  end
255  
-
256  
-  def ansi_escape(codes)
257  
-    codes = codes.join(";") if codes.kind_of?(Array)
258  
-    return "\e[#{codes}m#{self}\e[0m"
259  
-  end
260  
-
261  
-  def bold_green
262  
-    self.ansi_escape([1,32])
263  
-  end
264  
-
265  
-  def underline
266  
-    self.ansi_escape(4)
267  
-  end
268  
-
269  
-  def bright
270  
-    self.ansi_escape(1)
271  
-  end
272  
-end

0 notes on commit 702f533

Please sign in to comment.
Something went wrong with that request. Please try again.