use style.css for new installs, refactor new install to use store_file

This commit is contained in:
Kyle Drake 2014-11-06 14:05:34 -08:00
parent 42e21bce9a
commit 53d25cba1d
6 changed files with 39 additions and 23 deletions

View file

@ -296,12 +296,24 @@ class Site < Sequel::Model
FileUtils.mkdir_p files_path FileUtils.mkdir_p files_path
%w{index not_found}.each do |name| %w{index not_found}.each do |name|
File.write files_path("#{name}.html"), render_template("#{name}.erb") tmpfile = Tempfile.new "newinstall-#{name}"
tmpfile.write render_template("#{name}.erb")
tmpfile.close
store_file "#{name}.html", tmpfile, new_install: true
purge_cache "/#{name}.html" purge_cache "/#{name}.html"
ScreenshotWorker.perform_async values[:username], "#{name}.html" ScreenshotWorker.perform_async values[:username], "#{name}.html"
end end
FileUtils.cp template_file_path('cat.png'), files_path('cat.png') tmpfile = Tempfile.new 'style.css'
tmpfile.close
FileUtils.cp template_file_path('style.css'), tmpfile.path
store_file 'style.css', tmpfile, new_install: true
tmpfile = Tempfile.new 'cat.png'
tmpfile.close
FileUtils.cp template_file_path('cat.png'), tmpfile.path
store_file 'cat.png', tmpfile, new_install: true
end end
def get_file(path) def get_file(path)
@ -451,7 +463,7 @@ class Site < Sequel::Model
PurgeCacheWorker.perform_async payload PurgeCacheWorker.perform_async payload
end end
def store_file(path, uploaded) def store_file(path, uploaded, opts={})
relative_path = scrubbed_path path relative_path = scrubbed_path path
path = files_path path path = files_path path
@ -486,7 +498,8 @@ class Site < Sequel::Model
end end
pathname = Pathname(path) pathname = Pathname(path)
if pathname.basename.to_s == 'index.html'
if pathname.basename.to_s == 'index.html' && opts[:new_install] != true
begin begin
new_title = Nokogiri::HTML(File.read(uploaded.path)).css('title').first.text new_title = Nokogiri::HTML(File.read(uploaded.path)).css('title').first.text
rescue NoMethodError => e rescue NoMethodError => e
@ -533,7 +546,7 @@ class Site < Sequel::Model
ThumbnailWorker.perform_async values[:username], relative_path ThumbnailWorker.perform_async values[:username], relative_path
end end
SiteChange.record self, relative_path SiteChange.record self, relative_path unless opts[:new_install]
true true
end end

View file

@ -38,10 +38,16 @@ describe 'signup' do
fill_in_valid fill_in_valid
click_signup_button click_signup_button
site_created?.must_equal true site_created?.must_equal true
assert_equal( assert_equal(
true, true,
File.exist?(File.join(Site::SITE_FILES_ROOT, @site[:username], 'index.html')) File.exist?(File.join(Site::SITE_FILES_ROOT, @site[:username], 'index.html'))
) )
site = Site[username: @site[:username]]
site.site_files.length.must_equal 4
site.site_changed.must_equal false
site.site_updated_at.must_equal nil
end end
it 'fails to create for existing site' do it 'fails to create for existing site' do

View file

@ -72,8 +72,8 @@ describe 'site_files' do
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg') upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/img/test.jpg', 'image/jpeg')
last_response.body.must_match /successfully uploaded/i last_response.body.must_match /successfully uploaded/i
@site.reload.changed_count.must_equal 2 @site.reload.changed_count.must_equal 2
@site.site_files.count.must_equal 1 @site.site_files.select {|f| f.path == 'test.jpg'}.length.must_equal 1
digest.wont_equal @site.reload.site_files.first.sha1_hash digest.wont_equal @site.site_files_dataset.where(path: 'test.jpg').first.sha1_hash
end end
it 'works with directory path' do it 'works with directory path' do

View file

@ -3,16 +3,12 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>The web site of <%= username %></title> <title>The web site of <%= username %></title>
<style type="text/css">
/* This is a CSS comment. CSS is how you can add style to your website, such as colors, fonts,
and positioning of your HTML content. */
body { <!-- The style.css file allows you to change the look of your web pages.
background-color: white; If you include the next line in all your web pages, they will all share the same look.
color: black; This makes it easier to make new pages for your site. -->
font-family: Verdana;
} <link href="/style.css" rel="stylesheet" type="text/css" media="all">
</style>
</head> </head>
<body> <body>
<h1>Welcome to my Website!</h1> <h1>Welcome to my Website!</h1>
@ -22,7 +18,7 @@
<p>Here's how you can make <strong>bold</strong> and <em>italic</em> text.</p> <p>Here's how you can make <strong>bold</strong> and <em>italic</em> text.</p>
<p>Here's how you can add an image:</p> <p>Here's how you can add an image:</p>
<img src="cat.png"> <img src="/cat.png">
<p>Here's how to make a list:</p> <p>Here's how to make a list:</p>

View file

@ -3,11 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Not Found</title> <title>Not Found</title>
<style type="text/css"> <link href="/style.css" rel="stylesheet" type="text/css" media="all">
body {
font-family: Verdana;
}
</style>
</head> </head>
<body> <body>
<h1>Page Not Found</h1> <h1>Page Not Found</h1>

View file

@ -0,0 +1,5 @@
body {
background-color: white;
color: black;
font-family: Verdana;
}