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
%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"
ScreenshotWorker.perform_async values[:username], "#{name}.html"
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
def get_file(path)
@ -451,7 +463,7 @@ class Site < Sequel::Model
PurgeCacheWorker.perform_async payload
end
def store_file(path, uploaded)
def store_file(path, uploaded, opts={})
relative_path = scrubbed_path path
path = files_path path
@ -486,7 +498,8 @@ class Site < Sequel::Model
end
pathname = Pathname(path)
if pathname.basename.to_s == 'index.html'
if pathname.basename.to_s == 'index.html' && opts[:new_install] != true
begin
new_title = Nokogiri::HTML(File.read(uploaded.path)).css('title').first.text
rescue NoMethodError => e
@ -533,7 +546,7 @@ class Site < Sequel::Model
ThumbnailWorker.perform_async values[:username], relative_path
end
SiteChange.record self, relative_path
SiteChange.record self, relative_path unless opts[:new_install]
true
end

View file

@ -38,10 +38,16 @@ describe 'signup' do
fill_in_valid
click_signup_button
site_created?.must_equal true
assert_equal(
true,
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
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')
last_response.body.must_match /successfully uploaded/i
@site.reload.changed_count.must_equal 2
@site.site_files.count.must_equal 1
digest.wont_equal @site.reload.site_files.first.sha1_hash
@site.site_files.select {|f| f.path == 'test.jpg'}.length.must_equal 1
digest.wont_equal @site.site_files_dataset.where(path: 'test.jpg').first.sha1_hash
end
it 'works with directory path' do

View file

@ -3,16 +3,12 @@
<head>
<meta charset="UTF-8">
<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 {
background-color: white;
color: black;
font-family: Verdana;
}
</style>
<!-- The style.css file allows you to change the look of your web pages.
If you include the next line in all your web pages, they will all share the same look.
This makes it easier to make new pages for your site. -->
<link href="/style.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<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 add an image:</p>
<img src="cat.png">
<img src="/cat.png">
<p>Here's how to make a list:</p>

View file

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

View file

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