Skip to content

Commit

Permalink
remove projects directory
Browse files Browse the repository at this point in the history
  • Loading branch information
onigra committed Dec 16, 2015
1 parent 59d09c8 commit 08f53a5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
6 changes: 3 additions & 3 deletions lib/planaria/generator/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ def initialize(name)
end

def run
erb = ::ERB.new(File.read "./projects/#{@name}/html/index.html.erb")
yaml = ::YAML.load(File.read "./projects/#{@name}/config.yml")
erb = ::ERB.new(File.read "./#{@name}/html/index.html.erb")
yaml = ::YAML.load(File.read "./#{@name}/config.yml")

yaml.each do |k, v|
instance_variable_set("@#{k}", v)
end

::File.open "./projects/#{@name}/index.html", "w" do |file|
::File.open "./#{@name}/index.html", "w" do |file|
file.write erb.result(binding)
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/planaria/generator/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ def initialize(name)
end

def run
mkdir "./projects/#{@name}"
mkdir "./projects/#{@name}/html"
mkdir "./projects/#{@name}/css"
mkdir "./projects/#{@name}/js"
FileUtils.touch("./projects/#{@name}/html/index.html.erb")
FileUtils.touch("./projects/#{@name}/config.yml")
mkdir "./#{@name}"
mkdir "./#{@name}/html"
mkdir "./#{@name}/css"
mkdir "./#{@name}/js"
FileUtils.touch("./#{@name}/html/index.html.erb")
FileUtils.touch("./#{@name}/config.yml")
end

private
Expand Down
13 changes: 7 additions & 6 deletions spec/planaria/generator/builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))

RSpec.describe Planaria::Generator::Builder do
after { FileUtils.remove_dir "#{APP_ROOT}/projects", force: true }

describe "#run" do
let(:project_name) { "sample" }
let(:assert_html) do
<<-EOS
<!DOCTYPE html>
Expand Down Expand Up @@ -35,13 +32,17 @@
EOS
end

let(:project_name) { "foobar" }

before do
Planaria::Generator::Initializer.new(project_name).run
FileUtils.cp("#{APP_ROOT}/sample/index.html.erb", "#{APP_ROOT}/projects/#{project_name}/html/index.html.erb")
FileUtils.cp("#{APP_ROOT}/sample/config.yml", "#{APP_ROOT}/projects/#{project_name}/config.yml")
FileUtils.cp("#{APP_ROOT}/sample/index.html.erb", "#{APP_ROOT}/#{project_name}/html/index.html.erb")
FileUtils.cp("#{APP_ROOT}/sample/config.yml", "#{APP_ROOT}/#{project_name}/config.yml")
Planaria::Generator::Builder.new(project_name).run
end

it { expect(File.read "#{APP_ROOT}/projects/#{project_name}/index.html").to eq assert_html }
after { FileUtils.remove_dir "#{APP_ROOT}/#{project_name}", force: true }

it { expect(File.read "#{APP_ROOT}/#{project_name}/index.html").to eq assert_html }
end
end
48 changes: 26 additions & 22 deletions spec/planaria/generator/initializer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
require File.expand_path(File.join('../../', 'spec_helper'), File.dirname(__FILE__))

RSpec.describe Planaria::Generator::Initializer do
after { FileUtils.remove_dir "#{APP_ROOT}/projects", force: true }

describe "#run" do
context "run at once" do
let(:project_name) { "sample" }
let(:project_name) { "foobar" }
let(:initializer) { described_class.new project_name }

before { initializer.run }
after { FileUtils.remove_dir "#{APP_ROOT}/#{project_name}", force: true }

it do
aggregate_failures do
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name}")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name}/html")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name}/css")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name}/js")).to be_truthy
expect(File.exist?("#{APP_ROOT}/projects/#{project_name}/html/index.html.erb")).to be_truthy
expect(File.exist?("#{APP_ROOT}/projects/#{project_name}/config.yml")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name}")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name}/html")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name}/css")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name}/js")).to be_truthy
expect(File.exist?("#{APP_ROOT}/#{project_name}/html/index.html.erb")).to be_truthy
expect(File.exist?("#{APP_ROOT}/#{project_name}/config.yml")).to be_truthy
end
end
end
Expand All @@ -31,21 +30,26 @@
described_class.new(project_name2).run
end

after do
FileUtils.remove_dir "#{APP_ROOT}/#{project_name1}", force: true
FileUtils.remove_dir "#{APP_ROOT}/#{project_name2}", force: true
end

it do
aggregate_failures do
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name1}")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name1}/html")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name1}/css")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name1}/js")).to be_truthy
expect(File.exist?("#{APP_ROOT}/projects/#{project_name1}/html/index.html.erb")).to be_truthy
expect(File.exist?("#{APP_ROOT}/projects/#{project_name1}/config.yml")).to be_truthy

expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name2}")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name2}/html")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name2}/css")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/projects/#{project_name2}/js")).to be_truthy
expect(File.exist?("#{APP_ROOT}/projects/#{project_name2}/html/index.html.erb")).to be_truthy
expect(File.exist?("#{APP_ROOT}/projects/#{project_name2}/config.yml")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name1}")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name1}/html")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name1}/css")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name1}/js")).to be_truthy
expect(File.exist?("#{APP_ROOT}/#{project_name1}/html/index.html.erb")).to be_truthy
expect(File.exist?("#{APP_ROOT}/#{project_name1}/config.yml")).to be_truthy

expect(Dir.exist?("#{APP_ROOT}/#{project_name2}")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name2}/html")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name2}/css")).to be_truthy
expect(Dir.exist?("#{APP_ROOT}/#{project_name2}/js")).to be_truthy
expect(File.exist?("#{APP_ROOT}/#{project_name2}/html/index.html.erb")).to be_truthy
expect(File.exist?("#{APP_ROOT}/#{project_name2}/config.yml")).to be_truthy
end
end
end
Expand Down

0 comments on commit 08f53a5

Please sign in to comment.