Adding feature to allow users to choose a syntaxhighlighter theme per project

This commit is contained in:
Nathan Adams 2014-03-12 21:30:54 -05:00
parent 822e107958
commit 7ac8142fc6
8 changed files with 138 additions and 3 deletions

View File

@ -38,6 +38,10 @@ class IDF_FileUtil
'skin', 'sln', 'svc', 'vala', 'vb', 'vbproj', 'vbs', 'wsdl', 'xhtml', 'skin', 'sln', 'svc', 'vala', 'vb', 'vbproj', 'vbs', 'wsdl', 'xhtml',
'xml', 'xsd', 'xsl', 'xslt'); 'xml', 'xsd', 'xsl', 'xslt');
public static $map = array("h" => "cpp", "hpp" => "cpp", "rc"=>"text", "sh"=>"bash", "cs"=>"csharp");
public static $syntaxhighlightext = array("as3", "cf", "cpp", "c", "css", "pas", "diff", "patch", "erl", "java", "jfx", "js", "pl", "php", "py", "rb", "sass", "scss", "scala", "sql", "vb", );
/** /**
* Test if an extension is supported by the syntax highlighter. * Test if an extension is supported by the syntax highlighter.
* *
@ -72,7 +76,14 @@ class IDF_FileUtil
} }
return Pluf_Template::markSafe(implode("\n", $table));*/ return Pluf_Template::markSafe(implode("\n", $table));*/
//var_dump($fileinfo); //var_dump($fileinfo);
$content = '<script type="syntaxhighlighter" class="brush: ' . $fileinfo[2] . '">' . $content . '</script>'; $ext = "";
if (in_array($fileinfo[2], self::$syntaxhighlightext))
$ext = $fileinfo[2];
elseif (array_key_exists($fileinfo[2], self::$map))
$ext = self::$map[$fileinfo[2]];
else
$ext = "text";
$content = '<script type="syntaxhighlighter" class="brush: ' . $ext . '">' . $content . '</script>';
return Pluf_Template::markSafe($content); return Pluf_Template::markSafe($content);
} }

View File

@ -33,7 +33,17 @@ class IDF_Form_ProjectConf extends Pluf_Form
{ {
$this->project = $extra['project']; $this->project = $extra['project'];
$this->user = $extra["user"]; $this->user = $extra["user"];
$conf = $this->project->getConf(); $conf = $this->project->getConf();
$options = array(
'Default' => __('Default'),
'Django' => __('Django'),
'Eclipse' => __('Eclipse'),
'Emacs' => __('Emacs'),
'FadeToGrey' => __('FadeToGrey'),
'MDUltra' => __('MDUltra'),
'Midnight' => __('Midnight'),
'RDark' => __('RDark'),
);
// Basic part // Basic part
$this->fields['name'] = new Pluf_Form_Field_Varchar(array('required' => true, $this->fields['name'] = new Pluf_Form_Field_Varchar(array('required' => true,
@ -59,6 +69,15 @@ class IDF_Form_ProjectConf extends Pluf_Form
'initial' => $conf->getVal('external_project_url'), 'initial' => $conf->getVal('external_project_url'),
)); ));
$this->fields['syntaxtheme'] = new Pluf_Form_Field_Varchar(
array('required' => true,
'label' => __('Syntax Highlight Theme'),
'initial' => ($this->project->syntaxtheme) ? $this->project->syntaxtheme : "Default",
'widget_attrs' => array('choices' => $options),
'widget' => 'Pluf_Form_Widget_SelectInput',
));
if ($this->user->administrator) if ($this->user->administrator)
{ {
$this->fields['enableads'] = new Pluf_Form_Field_Boolean( $this->fields['enableads'] = new Pluf_Form_Field_Boolean(
@ -208,6 +227,7 @@ class IDF_Form_ProjectConf extends Pluf_Form
$this->project->shortdesc = $this->cleaned_data['shortdesc']; $this->project->shortdesc = $this->cleaned_data['shortdesc'];
$this->project->description = $this->cleaned_data['description']; $this->project->description = $this->cleaned_data['description'];
$this->project->batchAssoc('IDF_Tag', $tagids); $this->project->batchAssoc('IDF_Tag', $tagids);
$this->project->syntaxtheme = $this->cleaned_data["syntaxtheme"];
if ($this->user->administrator) if ($this->user->administrator)
$this->project->enableads = $this->cleaned_data['enableads']; $this->project->enableads = $this->cleaned_data['enableads'];
$this->project->update(); $this->project->update();

View File

@ -0,0 +1,36 @@
<?php
function IDF_Migrations_29EnableAds_up()
{
$table = Pluf::factory('IDF_Project')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " ADD COLUMN `enableads` int(11) NULL AFTER `current_activity`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
if (!isset($sql[$engine])) {
throw new Exception('SQLite complex migration not supported.');
}
$db->execute($sql[$engine]);
}
function IDF_Migrations_28OTPKey_down()
{
$table = Pluf::factory('IDF_Project')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " DROP COLUMN `enableads`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
if (!isset($sql[$engine])) {
throw new Exception('SQLite complex migration not supported.');
}
$db->execute($sql[$engine]);
}

View File

@ -0,0 +1,36 @@
<?php
function IDF_Migrations_30SyntaxHighlightTheme_up()
{
$table = Pluf::factory('IDF_Project')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " ADD COLUMN `syntaxtheme` VARCHAR(50) NULL AFTER `enableads`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
if (!isset($sql[$engine])) {
throw new Exception('SQLite complex migration not supported.');
}
$db->execute($sql[$engine]);
}
function IDF_Migrations_28OTPKey_down()
{
$table = Pluf::factory('IDF_Project')->getSqlTable();
$sql = array();
$sql["MySQL"] = "ALTER TABLE " . $table . " DROP COLUMN `syntaxtheme`;";
$db = Pluf::db();
$engine = Pluf::f('db_engine');
if (!isset($sql[$engine])) {
throw new Exception('SQLite complex migration not supported.');
}
$db->execute($sql[$engine]);
}

View File

@ -116,6 +116,15 @@ class IDF_Project extends Pluf_Model
'verbose' => __('enableads'), 'verbose' => __('enableads'),
'default' => 1, 'default' => 1,
), ),
'syntaxtheme' =>
array(
'type' => 'Pluf_DB_Field_Text',
'blank' => false,
'verbose' => __('syntaxtheme'),
'default' => "Default",
"size" => 50
)
); );
$activityTable = $this->_con->pfx.'idf_projectactivities'; $activityTable = $this->_con->pfx.'idf_projectactivities';
$tagTable = $this->_con->pfx.'idf_project_idf_tag_assoc'; $tagTable = $this->_con->pfx.'idf_project_idf_tag_assoc';

View File

@ -29,6 +29,13 @@ $ctl[] = array('regex' => '#^/$#',
'model' => 'IDF_Views', 'model' => 'IDF_Views',
'method' => 'index'); 'method' => 'index');
$ctl[] = array('regex' => '#^/u/(.*)/$#',
'base' => $base,
'model' => 'IDF_Views_User',
'method' => 'view',
'name' => 'idf_user_view');
$ctl[] = array('regex' => '#^/projects/$#', $ctl[] = array('regex' => '#^/projects/$#',
'base' => $base, 'base' => $base,
'model' => 'IDF_Views', 'model' => 'IDF_Views',

View File

@ -76,6 +76,13 @@
<td>{if $form.f.enableads.errors}{$form.f.enableads.fieldErrors}{/if} <td>{if $form.f.enableads.errors}{$form.f.enableads.fieldErrors}{/if}
{$form.f.enableads|unsafe} {$form.f.enableads|unsafe}
</td> </td>
</tr>
<tr>
<th>{$form.f.syntaxtheme.labelTag}:</th>
<td>{if $form.f.syntaxtheme.errors}{$form.f.syntaxtheme.fieldErrors}{/if}
{$form.f.syntaxtheme|unsafe}
</td>
</tr>
<tr><td>&nbsp;</td> <tr><td>&nbsp;</td>
<td> <td>
<input type="submit" name="submit" value="{trans 'Save Changes'}" /> <input type="submit" name="submit" value="{trans 'Save Changes'}" />

View File

@ -40,7 +40,16 @@
<script type="text/javascript" src="{media '/idf/js/syntaxhighlight/shAutoloader.js'}"></script> <script type="text/javascript" src="{media '/idf/js/syntaxhighlight/shAutoloader.js'}"></script>
<link rel="stylesheet" type="text/css" href="{media '/idf/css/syntaxhighlight/shCore.css'}" /> <link rel="stylesheet" type="text/css" href="{media '/idf/css/syntaxhighlight/shCore.css'}" />
<link rel="stylesheet" type="text/css" href="{media '/idf/css/syntaxhighlight/shCoreDefault.css'}" /> {if $project}
{if $project.syntaxtheme}
<link rel="stylesheet" type="text/css" href="{media '/idf/css/syntaxhighlight/shTheme'}{$project.syntaxtheme}.css" />
{else}
<link rel="stylesheet" type="text/css" href="{media '/idf/css/syntaxhighlight/shThemeDefault.css'}" />
{/if}
{else}
<link rel="stylesheet" type="text/css" href="{media '/idf/css/syntaxhighlight/shThemeDefault.css'}" />
{/if}
{appversion} {appversion}
</head> </head>
<body> <body>