support for page creation

This commit is contained in:
Kyle Drake 2013-06-23 20:49:36 -07:00
parent ed240b44f4
commit d7db5913f3
5 changed files with 79 additions and 13 deletions

47
app.rb
View file

@ -28,7 +28,12 @@ end
get '/blog' do
# expires 500, :public, :must_revalidate
return File.read File.join(DIR_ROOT, 'public', 'sites', 'kyledrake', 'blog.html')
return File.read File.join(DIR_ROOT, 'public', 'sites', 'blog', 'blog.html')
end
get '/blog/:id-:name' do
# expires 500, :public, :must_revalidate
return File.read File.join(DIR_ROOT, 'public', 'sites', 'blog', "blog-#{params[:id]}.html")
end
get '/new' do
@ -99,15 +104,47 @@ get '/signout' do
redirect '/'
end
get '/about' do
slim :'about'
end
get '/site_files/new_page' do
require_login
slim :'site_files/new_page'
end
post '/site_files/create_page' do
require_login
@errors = []
params[:pagefilename].gsub!(/[^a-zA-Z0-9_\-.]/, '')
params[:pagefilename].gsub!(/\.html$/i, '')
if params[:pagefilename].nil? || params[:pagefilename].empty?
@errors << 'You must provide a file name.'
halt slim(:'site_files/new_page')
end
name = "#{params[:pagefilename]}.html"
path = site_file_path name
if File.exist? path
@errors << %{Web page "#{name}" already exists! Choose another name.}
halt slim(:'site_files/new_page')
end
File.write path, slim(:'templates/index', pretty: true, layout: false)
flash[:success] = %{#{name} was created! <a style="color: #FFFFFF; text-decoration: underline" href="/site_files/text_editor/#{name}">Click here to edit it</a>.}
redirect '/dashboard'
end
get '/site_files/new' do
require_login
slim :'site_files/new'
end
get '/about' do
slim :'about'
end
post '/site_files/upload' do
require_login
@errors = []

View file

@ -64,8 +64,11 @@ javascript:
.row style="margin-top: 20px"
.span5
<a href="/site_files/new" class="btn btn-large btn-success" style="margin-bottom:20px">Upload New File</a>
div
a href="/site_files/new" class="btn btn-large btn-success" style="margin-bottom:20px" Upload New File
div
a href="/site_files/new_page" class="btn btn-large btn-success" style="margin-bottom: 20px" Create New HTML Page
h4: a href="/site_files/#{current_site.username}.zip" Download Entire Site
form method="POST" action="/site_files/delete" id="deleteFilenameForm"

View file

@ -26,11 +26,12 @@
td With donations. It's not that expensive. If you feel this is a useful service, <a href="/about">click here to contribute!</a>
.row
.span5.offset1
h2: a href="/browse" BROWSE EXISTING SITES
.span5.offset1
h2: a href="/new" CREATE A WEB SITE
.span5.offset2
a.btn.btn-large.btn-success style="font-size: 20pt" href="/browse" Browse Existing Sites
.span5
a.btn.btn-large.btn-success style="font-size: 20pt" href="/new" Create a Web Site
h5 Returning users: <a href="/signin">Sign In</a>
.row
.span6.offset3
h4 style="line-height: 22pt" There are <b>#{Server.first.slots_available}</b> web site spaces remaining.<br>After that, we need your help to get another server.<br><a href="/about">HELP NEOCITIES PROSPER</a>
h4 style="line-height: 22pt" There are <b>#{Server.first.slots_available}</b> web site spaces remaining.<br>After that, we need your help to get another server.
div.text-center: a class="btn btn-large btn-success" href="/about" Help Neocities Prosper

View file

@ -35,7 +35,7 @@ html
- flash.keys.each do |key|
div class="alert alert-#{key}"
button.close type="button" data-dismiss="alert" &times;
= flash[key]
== flash[key]
container
== yield

View file

@ -0,0 +1,25 @@
- if @errors
.row
.span8.offset2
div.alert.alert-error
h3 There were errors, please correct:
- @errors.each do |error|
h5 = error
.row
.span12.text-center
h1 Create new HTML page
.row
.span12.text-center
form method="POST" action="/site_files/create_page" enctype="multipart/form-data"
input name="csrf_token" type="hidden" value="#{csrf_token}"
h4 What's the name of your page?
h4: input type="text" name="pagefilename".html
p: input.btn.btn-success.btn-large type="submit" value="Create Page"
.row
.span6.offset3
h5 Note: We will automatically scrub any characters not matching: a-z A-Z 0-9 _ - .
h5 Page must not already exist.
h5 If you want to make this the index page (and an index page doesn't exist), name it <strong>index.html</strong>.