mirror of
https://github.com/perlbot/perlbuut-pastebin
synced 2025-06-07 14:17:26 -04:00
Add ruby. need to rethink how to do the languages so they have an order
This commit is contained in:
parent
39f4aeb9ea
commit
2a65124acc
5 changed files with 52 additions and 2 deletions
|
@ -14,7 +14,7 @@ use App::Controller::Apiv1;
|
|||
use App::Model::Paste;
|
||||
use App::Model::Eval;
|
||||
use App::Model::Perlbot;
|
||||
|
||||
use App::Model::Languages;
|
||||
|
||||
sub startup {
|
||||
my $self = shift;
|
||||
|
@ -36,6 +36,7 @@ sub startup {
|
|||
$self->helper(paste => sub {state $paste = App::Model::Paste->new});
|
||||
$self->helper(eval => sub {state $eval = App::Model::Eval->new});
|
||||
$self->helper(perlbot => sub {state $perlbot = App::Model::Perlbot->new});
|
||||
$self->helper(languages => sub {state $languages = App::Model::Languages->new});
|
||||
|
||||
$self->setup_routes();
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ sub to_root {
|
|||
|
||||
sub root {
|
||||
my $c = shift;
|
||||
$c->stash({languages => $c->languages->get_languages});
|
||||
$c->stash({pastedata => q{}, channels => $cfg->{announce}{channels}, page_tmpl => 'editor.html'});
|
||||
$c->render("page");
|
||||
};
|
||||
|
@ -69,6 +70,7 @@ sub edit_paste {
|
|||
my $row = $c->paste->get_paste($pasteid);
|
||||
|
||||
if ($row->{when}) {
|
||||
$c->stash({languages => $c->languages->get_languages});
|
||||
$c->stash({pastedata => $row->{paste}, channels =>$cfg->{announce}{channels}});
|
||||
$c->stash({page_tmpl => 'editor.html'});
|
||||
|
||||
|
@ -100,6 +102,7 @@ sub get_paste {
|
|||
|
||||
if ($row) {
|
||||
$c->stash($row);
|
||||
$c->stash({language_mode => $c->languages->language_to_acemode($row->{language})});
|
||||
$c->stash({page_tmpl => 'viewer.html'});
|
||||
$c->stash({eval => $c->eval->get_eval($pasteid, $row->{paste}, $row->{language})});
|
||||
$c->stash({paste_id => $pasteid});
|
||||
|
|
36
lib/App/Model/Languages.pm
Normal file
36
lib/App/Model/Languages.pm
Normal file
|
@ -0,0 +1,36 @@
|
|||
package App::Model::Languages;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Mojo::Base '-base';
|
||||
|
||||
my %langs = (
|
||||
"perl" => {mode => "perl", description => "Perl (blead/git)"},
|
||||
"perl4" => {mode => "perl", description => "Perl 4.0.36"},
|
||||
"perl5.5" => {mode => "perl", description => "Perl 5.5"},
|
||||
"perl5.6" => {mode => "perl", description => "Perl 5.6"},
|
||||
"perl5.8" => {mode => "perl", description => "Perl 5.8"},
|
||||
"perl5.10" => {mode => "perl", description => "Perl 5.10"},
|
||||
"perl5.12" => {mode => "perl", description => "Perl 5.12"},
|
||||
"perl5.14" => {mode => "perl", description => "Perl 5.14"},
|
||||
"perl5.16" => {mode => "perl", description => "Perl 5.16"},
|
||||
"perl5.18" => {mode => "perl", description => "Perl 5.18"},
|
||||
"perl5.20" => {mode => "perl", description => "Perl 5.20"},
|
||||
"perl5.22" => {mode => "perl", description => "Perl 5.22"},
|
||||
"perl5.24" => {mode => "perl", description => "Perl 5.24"},
|
||||
"text" => {mode => "text", description => "Plain text"},
|
||||
"ruby" => {mode => "ruby", description => "Ruby (2.1)"},
|
||||
);
|
||||
|
||||
sub language_to_acemode {
|
||||
my ($self, $lang) = @_;
|
||||
|
||||
return $langs{$lang}{mode} // "text";
|
||||
}
|
||||
|
||||
sub get_languages {
|
||||
return \%langs;
|
||||
}
|
||||
|
||||
1;
|
|
@ -95,6 +95,7 @@
|
|||
<label>Language</label>
|
||||
<select name="language" id="language">
|
||||
<option value="perl" data-lang="perl">Perl (blead)</option>
|
||||
<option value="ruby" data-lang="ruby">Ruby (2.1)</option>
|
||||
<option value="text" data-lang="text">Text</option>
|
||||
<option value="perl5.24" data-lang="perl">Perl 5.24</option>
|
||||
<option value="perl5.22" data-lang="perl">Perl 5.22</option>
|
||||
|
@ -207,6 +208,14 @@
|
|||
$("#raw_editor").on("change", use_editor);
|
||||
editor = ace.edit("editor");
|
||||
//editor.setTheme("ace/theme/twilight");
|
||||
|
||||
|
||||
$("#language").on('change', function () {
|
||||
var language = $('#language option').filter(':selected').attr('data-lang');
|
||||
console.log("language: ", language);
|
||||
editor.session.setMode("ace/mode/" + language);
|
||||
});
|
||||
|
||||
editor.session.setMode("ace/mode/perl");
|
||||
|
||||
// editor.setOptions({fontFamily: ['AnonymousPro', 'monospace', 'mono']});
|
||||
|
|
|
@ -82,7 +82,8 @@
|
|||
<script>
|
||||
var editor = ace.edit("editor");
|
||||
//editor.setTheme("ace/theme/twilight");
|
||||
editor.session.setMode("ace/mode/perl");
|
||||
|
||||
editor.session.setMode("ace/mode/[% language_mode %]");
|
||||
|
||||
var use_editor = function() {
|
||||
if ($("#raw_editor").is(":checked")) {
|
||||
|
|
Loading…
Add table
Reference in a new issue