make editor theme stick, and get rid of slim

This commit is contained in:
Kyle Drake 2014-08-01 22:37:38 -07:00
parent 7a751e811e
commit 933fb9fcfd
8 changed files with 180 additions and 190 deletions

View file

@ -3,7 +3,6 @@ source 'https://rubygems.org'
gem 'sinatra' gem 'sinatra'
gem 'redis' gem 'redis'
gem 'sequel', '4.8.0' gem 'sequel', '4.8.0'
gem 'slim'
gem 'bcrypt' gem 'bcrypt'
gem 'sinatra-flash', require: 'sinatra/flash' gem 'sinatra-flash', require: 'sinatra/flash'
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile' gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'

View file

@ -167,11 +167,7 @@ GEM
sinatra (>= 1.0.0) sinatra (>= 1.0.0)
sinatra-xsendfile (0.4.2) sinatra-xsendfile (0.4.2)
sinatra (>= 0.9.1) sinatra (>= 0.9.1)
slim (2.0.2)
temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1)
slop (3.5.0) slop (3.5.0)
temple (0.6.7)
tilt (1.4.1) tilt (1.4.1)
timers (1.1.0) timers (1.1.0)
treetop (1.4.15) treetop (1.4.15)
@ -234,7 +230,6 @@ DEPENDENCIES
sinatra sinatra
sinatra-flash sinatra-flash
sinatra-xsendfile sinatra-xsendfile
slim
stripe! stripe!
tilt tilt
webmock webmock

8
app.rb
View file

@ -112,6 +112,12 @@ get '/site/:username' do |username|
erb :'site', locals: {site: site, is_current_site: site == current_site} erb :'site', locals: {site: site, is_current_site: site == current_site}
end end
post '/site/:username/set_editor_theme' do
require_login
current_site.update editor_theme: params[:editor_theme]
'ok'
end
post '/site/:username/comment' do |username| post '/site/:username/comment' do |username|
require_login require_login
@ -641,7 +647,7 @@ get '/site_files/text_editor/:filename' do |filename|
flash[:error] = 'We could not find the requested file.' flash[:error] = 'We could not find the requested file.'
redirect '/dashboard' redirect '/dashboard'
end end
slim :'site_files/text_editor', indent: false erb :'site_files/text_editor'
end end
post '/site_files/save/:filename' do |filename| post '/site_files/save/:filename' do |filename|

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_column :sites, :editor_theme, :text
}
down {
DB.drop_column :sites, :editor_theme
}
end

View file

@ -39,6 +39,8 @@
<script> <script>
var RecaptchaOptions = {theme: 'clean'} var RecaptchaOptions = {theme: 'clean'}
</script> </script>
<script src="/assets/scripts/jquery-1.11.0.min.js"></script>
</head> </head>
<body class="interior"> <body class="interior">
@ -50,7 +52,6 @@
<%== erb :'_footer', layout: false %> <%== erb :'_footer', layout: false %>
</footer> </footer>
<script src="/assets/scripts/jquery-1.11.0.min.js"></script>
<script src="/assets/scripts/underscore-min.js"></script> <script src="/assets/scripts/underscore-min.js"></script>
<script src="/assets/scripts/nav.min.js"></script> <script src="/assets/scripts/nav.min.js"></script>
<script src="/js/bootstrap.min.js"></script> <script src="/js/bootstrap.min.js"></script>

View file

@ -1,55 +0,0 @@
doctype html
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
title Neocities #{@title.nil? ? '' : " - #{@title}"}
link href="/favicon.ico" rel="icon" type="image/x-icon"
link href="/css/bootstrap.min.css" rel="stylesheet"
link href="/css/bootstrap-responsive.min.css" rel="stylesheet"
link href="/css/font-awesome.min.css" rel="stylesheet"
link href="/css/styles.css" rel="stylesheet"
meta property="og:title" content="NeoCities"
meta property="og:description" content="NeoCities is the new Geocities. Create your own free home page, and do whatever you want with it."
meta name="csrf-token" content="#{csrf_token}"
script src="/assets/scripts/jquery-1.11.0.min.js"
link href="/assets/css/neo.css" rel="stylesheet" type="text/css" media="all"
script src="/assets/scripts/nav.min.js"
body.interior
a id="top"
== erb :'_header', layout: false
.page
.container
- flash.keys.each do |key|
- next unless %i{success error}.include? key
div class="alert alert-#{key}"
button.close type="button" data-dismiss="alert" &times;
== flash[key]
== yield
script src="/js/bootstrap.min.js"
javascript:
!function(){
var csrf_token = $('meta[name="csrf-token"]').attr('content');
$(document).ajaxSend(function(ev, jqxhr){
jqxhr.setRequestHeader('X-CSRF-Token', csrf_token);
});
}();
javascript:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-41925541-1', 'neocities.org');
ga('send', 'pageview');
footer class="footer-Base"
== erb :'_footer', layout: false

View file

@ -0,0 +1,162 @@
<style>
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.theme-Code{
float:right;
position:relative;
top:-50px;
}
</style>
<div class="header-Outro">
<div class="row content single-Col">
<h1>Editing <%= params[:filename] %></h1>
</div>
</div>
<div class="content">
<div class="row">
<div class="col col-50">
<p>
Theme:
<select id="theme" size="1" onchange="setTheme();" onkeyup="setTheme();">
<optgroup label="Bright">
<option value="ace/theme/chrome">Chrome</option>
<option value="ace/theme/clouds">Clouds</option>
<option value="ace/theme/crimson_editor">Crimson Editor</option>
<option value="ace/theme/dawn">Dawn</option>
<option value="ace/theme/dreamweaver">Dreamweaver</option>
<option value="ace/theme/eclipse">Eclipse</option>
<option value="ace/theme/github">GitHub</option>
<option value="ace/theme/solarized_light">Solarized Light</option>
<option value="ace/theme/textmate">TextMate</option>
<option value="ace/theme/tomorrow">Tomorrow</option>
<option value="ace/theme/xcode">XCode</option>
</optgroup>
<optgroup label="Dark">
<option value="ace/theme/ambiance">Ambiance</option>
<option value="ace/theme/chaos">Chaos</option>
<option value="ace/theme/clouds_midnight">Clouds Midnight</option>
<option value="ace/theme/cobalt">Cobalt</option>
<option value="ace/theme/idle_fingers">idleFingers</option>
<option value="ace/theme/kr_theme">krTheme</option>
<option value="ace/theme/merbivore">Merbivore</option>
<option value="ace/theme/merbivore_soft">Merbivore Soft</option>
<option value="ace/theme/mono_industrial">Mono Industrial</option>
<option value="ace/theme/monokai">Monokai</option>
<option value="ace/theme/pastel_on_dark">Pastel on dark</option>
<option value="ace/theme/solarized_dark" selected="selected">Solarized Dark</option>
<option value="ace/theme/terminal">Terminal</option>
<option value="ace/theme/tomorrow_night">Tomorrow Night</option>
<option value="ace/theme/tomorrow_night_blue">Tomorrow Night Blue</option>
<option value="ace/theme/tomorrow_night_bright">Tomorrow Night Bright</option>
<option value="ace/theme/tomorrow_night_eighties">Tomorrow Night 80s</option>
<option value="ace/theme/twilight">Twilight</option>
<option value="ace/theme/vibrant_ink">Vibrant Ink</option>
</optgroup>
</select>
</p>
</div>
</div>
<div class="row">
<div class="col col-100">
<div id="editor" style="width: 100%; height: 600px; position: relative; margin-bottom:25px"><%==encoding_fix(@file_data) %>
</div>
</div>
</div>
<div class="row">
<div class="col col-33">
<div class="txt-Center">
<a class="btn-Action" href="/dashboard" <i class="icon-remove"></i>&nbsp;&nbsp;Finish Without Saving</a>
</div>
</div>
<div class="col col-33">
<div class="txt-Center">
<a class="btn-Action" href="#" onclick="saveTextFile(false); return false" <i class="icon-save"></i>&nbsp;&nbsp;Save Changes</a>
</div>
</div>
<div class="col col-33">
<div class="txt-Center">
<a class="btn-Action" href="#" onclick="saveTextFile(true); return false" <i class="icon-save"></i>&nbsp;&nbsp;Save and Finish</a>
</div>
</div>
</div>
<div class="row">
<div class="col col-100 txt-Center">
<div id="editorUpdates" class="alert alert-success hidden">
<span></span>
</div>
</div>
</div>
</div>
<script src="/js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
function setTheme(name) {
var editorTheme = $('#theme option:selected')
editor.setTheme(editorTheme.val())
$.post('/site/<%= current_site.username %>/set_editor_theme', {
csrf_token: '<%= csrf_token %>',
editor_theme: editorTheme.text()
})
}
<% if current_site.editor_theme %>
$('#theme option').filter(function() {
return ($(this).text() == '<%= current_site.editor_theme %>')
}).prop('selected', true)
<% end %>
function saveTextFile(quit) {
$.ajax({
url: '/site_files/save/<%= params[:filename] %>?csrf_token=<%= csrf_token %>',
data: editor.getValue(),
processData: false,
contentType: false,
type: 'POST',
success: function(response){
if(response == 'ok') {
if(quit === true) {
window.location = '/dashboard';
} else {
$('#editorUpdates span').html('<i class="icon-save icon-2x"></i>&nbsp;&nbsp;<span style="font-size: 14pt">Your file has been saved.</span>');
setTimeout(function() {
$('#editorUpdates').fadeOut(); //.addClass('hidden');
}, 2000)
}
} else {
$('#editorUpdates span').text(response)
}
$('#editorUpdates').fadeIn()
$('#editorUpdates').removeClass('hidden')
}
})
}
var editor = {};
$(document).ready(function() {
editor = ace.edit("editor");
setTheme();
editor.getSession().setMode("ace/mode/html");
editor.getSession().setTabSize(2);
editor.getSession().setUseWrapMode(true);
editor.setFontSize(14);
editor.setShowPrintMargin(false);
});
</script>

View file

@ -1,127 +0,0 @@
css:
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.theme-Code{
float:right;
position:relative;
top:-50px;
}
.page
.content-Base
h2 Editing #{params[:filename]}
.theme-Code
p style="display:inline-block; margin-right:10px" Theme:
select id="theme" size="1" onchange="setTheme();" onkeyup="setTheme();"
optgroup label="Bright"
option value="ace/theme/chrome" Chrome
option value="ace/theme/clouds" Clouds
option value="ace/theme/crimson_editor" Crimson Editor
option value="ace/theme/dawn" Dawn
option value="ace/theme/dreamweaver" Dreamweaver
option value="ace/theme/eclipse" Eclipse
option value="ace/theme/github" GitHub
option value="ace/theme/solarized_light" Solarized Light
option value="ace/theme/textmate" TextMate
option value="ace/theme/tomorrow" Tomorrow
option value="ace/theme/xcode" XCode
optgroup label="Dark"
option value="ace/theme/ambiance" Ambiance
option value="ace/theme/chaos" Chaos
option value="ace/theme/clouds_midnight" Clouds Midnight
option value="ace/theme/cobalt" Cobalt
option value="ace/theme/idle_fingers" idleFingers
option value="ace/theme/kr_theme" krTheme
option value="ace/theme/merbivore" Merbivore
option value="ace/theme/merbivore_soft" Merbivore Soft
option value="ace/theme/mono_industrial" Mono Industrial
option value="ace/theme/monokai" Monokai
option value="ace/theme/pastel_on_dark" Pastel on dark
option value="ace/theme/solarized_dark" selected="selected" Solarized Dark
option value="ace/theme/terminal" Terminal
option value="ace/theme/tomorrow_night" Tomorrow Night
option value="ace/theme/tomorrow_night_blue" Tomorrow Night Blue
option value="ace/theme/tomorrow_night_bright" Tomorrow Night Bright
option value="ace/theme/tomorrow_night_eighties" Tomorrow Night 80s
option value="ace/theme/twilight" Twilight
option value="ace/theme/vibrant_ink" Vibrant Ink
<div id="editor" style="width: 100%; height: 600px; position: relative; margin-bottom:25px">#{{encoding_fix(@file_data)}}</div>
.row
.col.col-33.txt-Center style="margin-bottom:10px"
a.btn-Action href="/dashboard" <i class="icon-remove"></i>&nbsp;&nbsp;Finish Without Saving
.col.col-33.txt-Center style="margin-bottom:10px"
a.btn-Action href="#" onclick="saveTextFile(false); return false" <i class="icon-save"></i>&nbsp;&nbsp;Save Changes
.col.col-33.txt-Center
a.btn-Action href="#" onclick="saveTextFile(true); return false" <i class="icon-save"></i>&nbsp;&nbsp;Save and Finish
.row style="margin-top: 20px"
.span6.offset3.text-center
div id="editorUpdates" class="alert alert-success hidden"
span
script src="/js/ace/ace.js" type="text/javascript" charset="utf-8"
javascript:
function setTheme(name) {
editor.setTheme($('#theme').val());
}
function saveTextFile(quit) {
/*
$.post('/site_files/save/#{params[:filename]}', editor.getValue(), function(resp) {
if(resp == 'ok') {
$('#editorUpdates span').text('Your file has been saved.');
$('#editorUpdates').removeClass('hidden');
}
});
*/
$.ajax({
url: '/site_files/save/#{params[:filename]}',
data: editor.getValue(),
processData: false,
contentType: false,
type: 'POST',
success: function(response){
if(response == 'ok') {
if(quit === true) {
window.location = '/dashboard';
}
$('#editorUpdates span').html('<i class="icon-save icon-2x"></i>&nbsp;&nbsp;<span style="font-size: 14pt">Your file has been saved.</span>');
setTimeout(function() {
$('#editorUpdates').fadeOut(); //.addClass('hidden');
}, 2000);
} else {
$('#editorUpdates span').text(response);
}
$('#editorUpdates').fadeIn();
$('#editorUpdates').removeClass('hidden');
}
});
}
var editor = {};
$(document).ready(function() {
editor = ace.edit("editor");
setTheme();
editor.getSession().setMode("ace/mode/html");
editor.getSession().setTabSize(2);
editor.getSession().setUseWrapMode(true);
editor.setFontSize(14);
editor.setShowPrintMargin(false);
});