forked from mthiede/concrete
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added selection support for concrete syntax
- Loading branch information
Showing
7 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Concrete.UI.PreferencesDialog = Class.create(Concrete.UI.AbstractDialog, { | ||
|
||
initialize: function($super, options) { | ||
options = options || {}; | ||
var dialogElement = this._createDomElement(); | ||
$super(dialogElement, options); | ||
this.syntaxInput = dialogElement.down(".syntax_input"); | ||
}, | ||
|
||
_createDomElement: function() { | ||
if ($('ct_preferences_dialog')) return $('ct_preferences_dialog'); | ||
Element.insert($$('body').first(), { bottom: | ||
"<div id='ct_preferences_dialog' class='popup_dialog' style='display: none; position: fixed; z-index: 1000'>" + | ||
"<div class='shadow'></div>" + | ||
"<div class='dialog_box'>" + | ||
"<div class='title_bar'>Preferences" + | ||
"<a class='close_button'></a>" + | ||
"</div>" + | ||
"<div class='container'>" + | ||
"<p class='label'>Concrete Syntax</p>" + | ||
"<select class='dropdown_input syntax_input'>" + | ||
"</select>" + | ||
"<div style='text-align: center; margin: 10px'>" + | ||
"<input class='button_input proceed_button' type='button' value='OK' />" + | ||
"<input class='button_input cancel_button' type='button' value='Cancel' />" + | ||
"</div>" + | ||
"</div>" + | ||
"</div>" + | ||
"</div>" }); | ||
return $('ct_preferences_dialog'); | ||
}, | ||
|
||
_proceed: function() { | ||
new Ajax.Request("/setConcreteSyntax", { | ||
method: 'get', | ||
parameters: {"ident": this.syntaxInput.value}, | ||
onSuccess: function(transport) { | ||
}, | ||
onFailure: function() { | ||
} | ||
}); | ||
}, | ||
|
||
_buttonPressed: function(element) { | ||
if (element == this.dialogElement.down(".cancel_button")) { | ||
this.close(); | ||
} | ||
}, | ||
|
||
open: function($super, options) { | ||
$super(); | ||
new Ajax.Request("/concreteSyntaxes", { | ||
method: 'get', | ||
onSuccess: function(transport) { | ||
if (transport.responseText.isJSON()) { | ||
var synDesc = transport.responseText.evalJSON(); | ||
Element.replace(this.syntaxInput, | ||
"<select class='dropdown_input syntax_input'>" + | ||
synDesc.syntaxes.collect(function(s) { | ||
var selected = (s.ident == synDesc.selected) ? "selected" : ""; | ||
return "<option "+selected+" value=\""+s.ident+"\">"+s.name+"</option>"; | ||
}).join("") + | ||
"</select>" | ||
); | ||
this.syntaxInput = this.dialogElement.down(".syntax_input"); | ||
} | ||
}.bind(this), | ||
}); | ||
} | ||
|
||
}); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Concrete | ||
|
||
class ConcreteSyntaxProvider | ||
|
||
class ConcreteSyntax | ||
attr_accessor :ident, :dir, :name, :desc, :htmlTemplates, :cssStyleFile | ||
end | ||
|
||
def initialize(configDirs, logger) | ||
@configDirs = configDirs | ||
@logger = logger | ||
@selectedSyntax = nil | ||
end | ||
|
||
def selectedSyntax | ||
@selectedSyntax || syntaxes.first | ||
end | ||
|
||
def selectSyntax(ident) | ||
@selectedSyntax = syntaxes.find{|s| s.ident == ident} | ||
end | ||
|
||
def syntaxesAsJson | ||
'{ "syntaxes": [' + syntaxes.collect do |s| | ||
'{ "ident": "'+s.ident+'", "name": "'+s.name+'" }' | ||
end.join(", ") + '], "selected": "'+@selectedSyntax.andand.ident.to_s+'" }' | ||
end | ||
|
||
def syntaxes | ||
result = [] | ||
@configDirs.each do |cd| | ||
Dir.entries(cd).sort.each do |sd| | ||
next if sd == "." || sd == ".." | ||
syntaxDir = cd+"/"+sd | ||
templatesFile = syntaxDir + "/templates.html" | ||
styleFile = syntaxDir + "/style.css" | ||
unless File.exist?(templatesFile) || File.exist?(styleFile) | ||
@logger.warn("Concrete syntax dir without a templates.html or a style.css: #{syntaxDir}") | ||
next | ||
end | ||
s = ConcreteSyntax.new | ||
s.ident = syntaxDir.gsub("\\","/") | ||
s.dir = syntaxDir | ||
s.name = sd | ||
s.desc = "" | ||
s.cssStyleFile = styleFile if File.exist?(styleFile) | ||
s.htmlTemplates = File.read(templatesFile) if File.exist?(templatesFile) | ||
result << s | ||
end | ||
end | ||
result | ||
end | ||
|
||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters