Skip to content

Instantly share code, notes, and snippets.

@samuelkadolph
Last active December 20, 2015 17:49
Show Gist options
  • Save samuelkadolph/6171589 to your computer and use it in GitHub Desktop.
Save samuelkadolph/6171589 to your computer and use it in GitHub Desktop.

Revisions

  1. samuelkadolph revised this gist Mar 9, 2014. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -18,17 +18,22 @@ def replace(path, pattern, replacement)

    Dir["{app,config,test}/**/*.rb", "bin/*", "Gemfile", "Rakefile"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative \"\\1\" ")
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative \"\\1\"")
    replace(path, /^\s*#(?!!).*\n/, "")
    replace(path, /\A\n+/, "\n")
    replace(path, /\A\n+/, "")
    end

    replace("config.ru", /(?<!\w)'|'(?!\w)/, '"')
    replace("config.ru", /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require File.expand_path(\"../\\1\", __FILE__)")
    replace("config.ru", /^\s*#(?!!).*\n/, "")
    replace("config.ru", /\A\n+/, "\n")
    replace("config.ru", /\A\n+/, "")

    FileUtils.rm_rf("lib/assets")

    File.truncate("db/seeds.rb", 0)

    File.truncate("public/robots.txt", 0)

    FileUtils.rm_rf("vendor")

    FileUtils.mv("README.rdoc", "README.md")
  2. samuelkadolph revised this gist Mar 9, 2014. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ def replace(path, pattern, replacement)

    run "git init"
    run "git add --all"
    run "git commit -m 'Initial rails application'"
    run "git commit --message 'Initial rails application'"

    log :lean, "making the app lean"
    log :clean, "making the app clean"
    @@ -33,3 +33,6 @@ def replace(path, pattern, replacement)

    FileUtils.mv("README.rdoc", "README.md")
    File.truncate("README.md", 0)

    run "git add --all"
    run "git commit --message 'Lean and clean'"
  3. samuelkadolph revised this gist Mar 9, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -20,15 +20,16 @@ def replace(path, pattern, replacement)
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative \"\\1\" ")
    replace(path, /^\s*#(?!!).*\n/, "")
    replace(path, /\A\n+/, "")
    replace(path, /\A\n+/, "\n")
    end

    replace("config.ru", /(?<!\w)'|'(?!\w)/, '"')
    replace("config.ru", /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require File.expand_path(\"../\\1\", __FILE__)")
    replace("config.ru", /^\s*#(?!!).*\n/, "")
    replace("config.ru", /\A\n+/, "")
    replace("config.ru", /\A\n+/, "\n")

    FileUtils.rm_rf("lib/assets")
    FileUtils.rm_rf("vendor")

    FileUtils.mv("README.rdoc", "README.md")
    File.truncate("README.md", 0)
  4. samuelkadolph revised this gist Mar 9, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    def replace(path, pattern, replacement)
    File.open(path, "r+") do |file|
    contents = file.read

    file.truncate(0)
    file.pos = 0

    file << contents.gsub(pattern, replacement)
    end
    end
    @@ -18,7 +18,7 @@ def replace(path, pattern, replacement)

    Dir["{app,config,test}/**/*.rb", "bin/*", "Gemfile", "Rakefile"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative \"\\1\" ")
    replace(path, /^\s*#(?!!).*\n/, "")
    replace(path, /\A\n+/, "")
    end
  5. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ def replace(path, pattern, replacement)
    replace("config.ru", /^\s*#(?!!).*\n/, "")
    replace("config.ru", /\A\n+/, "")

    FileUtils.rm_rf("lib/assets", "vendor")
    FileUtils.rm_rf("lib/assets")
    FileUtils.rm_rf("vendor")
    FileUtils.mv("README.rdoc", "README.md")
    File.truncate("README.md", 0)
  6. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ def replace(path, pattern, replacement)
    log :lean, "making the app lean"
    log :clean, "making the app clean"

    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile"].each do |path|
    Dir["{app,config,test}/**/*.rb", "bin/*", "Gemfile", "Rakefile"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#(?!!).*\n/, "")
    @@ -28,5 +28,6 @@ def replace(path, pattern, replacement)
    replace("config.ru", /^\s*#(?!!).*\n/, "")
    replace("config.ru", /\A\n+/, "")

    FileUtils.rm_rf("lib/assets", "vendor")
    FileUtils.mv("README.rdoc", "README.md")
    File.truncate("README.md", 0)
  7. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -27,3 +27,6 @@ def replace(path, pattern, replacement)
    replace("config.ru", /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require File.expand_path(\"../\\1\", __FILE__)")
    replace("config.ru", /^\s*#(?!!).*\n/, "")
    replace("config.ru", /\A\n+/, "")

    FileUtils.mv("README.rdoc", "README.md")
    File.truncate("README.md", 0)
  8. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,14 @@ def replace(path, pattern, replacement)
    log :lean, "making the app lean"
    log :clean, "making the app clean"

    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile", "config.ru"].each do |path|
    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#(?!!).*\n/, "")
    replace(path, /\A\n+/, "")
    end

    replace("config.ru", /(?<!\w)'|'(?!\w)/, '"')
    replace("config.ru", /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require File.expand_path(\"../\\1\", __FILE__)")
    replace("config.ru", /^\s*#(?!!).*\n/, "")
    replace("config.ru", /\A\n+/, "")
  9. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ def replace(path, pattern, replacement)

    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#(?!!).*\n/, "")
    replace(path, /\A\n+/, "")
    end
  10. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,6 @@ def replace(path, pattern, replacement)
    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#.*$\n/, "")
    replace(path, /^\s*#(?!!).*\n/, "")
    replace(path, /\A\n+/, "")
    end
  11. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,12 @@ def replace(path, pattern, replacement)
    run "git add --all"
    run "git commit -m 'Initial rails application'"

    log :replace, "' with \""
    log :replace, ""
    log :remove, "comments"
    log :lean, "making the app lean"
    log :clean, "making the app clean"

    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#.*$\n/, "")
    replace(path, /\A\n+/, "")
    end
  12. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ def replace(path, pattern, replacement)
    log :replace, ""
    log :remove, "comments"

    Dir["{app,bin,config}/**/*.rb", "Gemfile", "Rakefile", "config.ru"].each do |path|
    Dir["{app,config}/**/*.rb", "bin/*", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#.*$\n/, "")
  13. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,6 @@ def replace(path, pattern, replacement)

    Dir["{app,bin,config}/**/*.rb", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\1\")")
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\\1\")")
    replace(path, /^\s*#.*$\n/, "")
    end
  14. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,6 @@ def replace(path, pattern, replacement)

    Dir["{app,bin,config}/**/*.rb", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\1\")")
    replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\1\")")
    replace(path, /^\s*#.*$\n/, "")
    end
  15. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,11 @@ def replace(path, pattern, replacement)
    run "git commit -m 'Initial rails application'"

    log :replace, "' with \""
    Dir["{app,config}/**/*.rb"].each do |path|
    log :replace, ""
    log :remove, "comments"

    Dir["{app,bin,config}/**/*.rb", "Gemfile", "Rakefile", "config.ru"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    replace(path, /require File\.expand_path\("..\/([^"]+)", __FILE__\)/, "require_relative(\"\1\")")
    replace(path, /^\s*#.*$\n/, "")
    end
  16. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ def replace(path, pattern, replacement)
    run "git add --all"
    run "git commit -m 'Initial rails application'"

    log :replace, "foo"
    log :replace, "' with \""
    Dir["{app,config}/**/*.rb"].each do |path|
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    end
  17. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,5 @@ def replace(path, pattern, replacement)

    log :replace, "foo"
    Dir["{app,config}/**/*.rb"].each do |path|
    replace(path, /(?<=^|\s)'|'(?=\s|$)/, '"')
    replace(path, /(?<!\w)'|'(?!\w)/, '"')
    end
  18. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ def replace(path, pattern, replacement)
    run "git add --all"
    run "git commit -m 'Initial rails application'"

    log :replace, "foo"
    Dir["{app,config}/**/*.rb"].each do |path|
    replace(path, /(?<=^|\s)'|'(?=\s|$)/, '"')
    end
  19. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ def replace(path, pattern, replacement)
    File.open(path, "r+") do |file|
    contents = file.read

    file.truncate
    file.truncate(0)
    file.pos = 0

    file << contents.gsub(pattern, replacement)
  20. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,18 @@
    def replace(path, pattern, replacement)
    File.open(path, "r+") do |file|
    contents = file.read

    file.truncate
    file.pos = 0

    file << contents.gsub(pattern, replacement)
    end
    end

    run "git init"
    run "git add --all"
    run "git commit -m 'Initial rails application'"

    run "sed -i '' \"s/'/\\\"/\" {app,config}/**/*.rb"
    Dir["{app,config}/**/*.rb"].each do |path|
    replace(path, /(?<=^|\s)'|'(?=\s|$)/, '"')
    end
  21. samuelkadolph revised this gist Aug 7, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template.rb
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,4 @@
    run "git add --all"
    run "git commit -m 'Initial rails application'"

    run "sed -i '' \"s/'/\"/\" {app,config}/**/*.rb"
    run "sed -i '' \"s/'/\\\"/\" {app,config}/**/*.rb"
  22. samuelkadolph created this gist Aug 7, 2013.
    5 changes: 5 additions & 0 deletions template.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    run "git init"
    run "git add --all"
    run "git commit -m 'Initial rails application'"

    run "sed -i '' \"s/'/\"/\" {app,config}/**/*.rb"