From: Sascha Peilicke
Slightly more sophisticated (and different) than 'spec' mode. Thus a
distinct one.
---
src/webui/app/views/project/prjconf.html.erb | 4 +-
src/webui/public/javascripts/cm2/mode/prjconf.js | 69 ++++++++++++++++++++++
2 files changed, 71 insertions(+), 2 deletions(-)
create mode 100644 src/webui/public/javascripts/cm2/mode/prjconf.js
diff --git a/src/webui/app/views/project/prjconf.html.erb b/src/webui/app/views/project/prjconf.html.erb
index 4259c90..9322bf1 100644
--- a/src/webui/app/views/project/prjconf.html.erb
+++ b/src/webui/app/views/project/prjconf.html.erb
@@ -7,8 +7,8 @@
<h3><%= @pagetitle %></h3>
<div style="margin-left: 15px; margin-right: 15px;">
<% if @project.can_edit?(session[:login]) %>
- <%= render :partial => "shared/editor", :locals => {:text => @config, :mode => 'spec', :save => {:url => {:controller => 'project', :action => 'save_prjconf'}, :method => 'POST', :data => {:project => @project, :config => '@@@'}}} %>
+ <%= render :partial => "shared/editor", :locals => {:text => @config, :mode => 'prjconf', :save => {:url => {:controller => 'project', :action => 'save_prjconf'}, :method => 'POST', :data => {:project => @project, :config => '@@@'}}} %>
<% else %>
- <%= render :partial => "shared/editor", :locals => {:text => @config, :mode => 'spec', :read_only => true} %>
+ <%= render :partial => "shared/editor", :locals => {:text => @config, :mode => 'prjconf', :read_only => true} %>
<% end %>
</div>
diff --git a/src/webui/public/javascripts/cm2/mode/prjconf.js b/src/webui/public/javascripts/cm2/mode/prjconf.js
new file mode 100644
index 0000000..ab47df1
--- /dev/null
+++ b/src/webui/public/javascripts/cm2/mode/prjconf.js
@@ -0,0 +1,69 @@
+// Quick and dirty prjconf file highlighting
+
+CodeMirror.defineMode("prjconf", function(config, modeConfig) {
+ var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/;
+ var prjconf = /^(Conflict|Ignore|Keep|Macros|Optflags|Order|Prefer|ExportFilter|Type|Patterntype|Preinstall|Repotype|Required|Runscripts|Substitute|Support|VMinstall):/;
+ var control_flow_macros = /^%(ifnarch|ifarch|if|else|endif|\|\||\&\&)/; // rpm control flow macros
+
+ return {
+ startState: function () {
+ return {
+ exportFilter: false,
+ controlFlow: false,
+ };
+ },
+ token: function (stream, state) {
+ var ch = stream.peek();
+ if (ch == "#") { stream.skipToEnd(); return "comment"; }
+
+ if (state.exportFilter) {
+ state.exportFilter = false;
+ if (stream.match(/^.*\$/)) {
+ return "string";
+ }
+ }
+
+ if (stream.sol()) {
+ var match;
+ if (match = stream.match(prjconf)) {
+ if (match[0] == "ExportFilter:") {
+ state.exportFilter = true;
+ }
+ return "builtin";
+ }
+ }
+
+ if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT'
+ if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}'
+
+ //TODO: Support expressions in control flow macros like '%if ! %foo || %bar && %spam':
+ if (stream.match(control_flow_macros)) {
+ state.controlFlow = true;
+ return "keyword";
+ }
+ //TODO: Match architectures only behind '%ifarch' ?!?
+ if (stream.match(arch)) { return "number"; }
+ //TODO: Include stuff like %attr(0775,root,root), not possible with stateless parser
+ if (stream.match(/^%[\w]+/)) { return "macro"; } // Macros like '%make_install'
+ if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}'
+
+ if (state.controlFlow) {
+ if (stream.match(/^(\!|\?|\=\=|\&\&|\|\|)/)) {
+ return "keyword"; // Even though 'operator' would be more correct, 'keyword' looks nicer ;-)
+ }
+ //TODO: Match '\"foo\"' strings, but don't forget that there may be macros inside,
+ if (stream.eol()) {
+ state.controlFlow = false;
+ }
+ }
+
+ //TODO: Include bash script sub-parser (CodeMirror supports that)
+
+ stream.next();
+ return null;
+ }
+ };
+});
+
+CodeMirror.defineMIME("text/x-prjconf", "prjconf");
+
--
1.7.7
--
To unsubscribe, e-mail: obs-commits+unsubscribe@opensuse.org
To contact the owner, e-mail: obs-commits+owner@opensuse.org