Created
August 19, 2011 19:32
-
-
Save dmitrig01/1157769 to your computer and use it in GitHub Desktop.
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
diff --git a/assets/js/codemirror.carto.js b/assets/js/codemirror.carto.js | |
index d45c74e..98f32ed 100644 | |
--- a/assets/js/codemirror.carto.js | |
+++ b/assets/js/codemirror.carto.js | |
@@ -111,6 +111,9 @@ CodeMirror.defineMode('carto', function(config, parserConfig) { | |
var context = state.stack[state.stack.length - 1]; | |
if (type == 'hash' && context == 'rule') { | |
style = 'carto-colorcode'; | |
+ if (parserConfig.onColor) { | |
+ parserConfig.onColor(stream.current()); | |
+ } | |
} else if (style == 'carto-identifier') { | |
if (context == 'rule') { | |
style = (valid_keywords[stream.current()] || valid_colors[stream.current()]) ? | |
diff --git a/test/support/init.sh b/test/support/init.sh | |
index e147042..7dc449e 100755 | |
--- a/test/support/init.sh | |
+++ b/test/support/init.sh | |
@@ -3,6 +3,6 @@ | |
rm -rf ./test/fixtures/files/{app.db,project,data,export} | |
cp -r ./test/fixtures/pristine/project ./test/fixtures/files | |
-psql -d postgres -c "DROP DATABASE IF EXISTS tilemill_test;" | |
-createdb -E UTF8 tilemill_test | |
-psql -d tilemill_test -f test/fixtures/tilemill_test.sql | |
+#psql -d postgres -c "DROP DATABASE IF EXISTS tilemill_test;" | |
+#createdb -E UTF8 tilemill_test | |
+#psql -d tilemill_test -f test/fixtures/tilemill_test.sql | |
diff --git a/views/Project.bones b/views/Project.bones | |
index 4fd31a8..f4f874c 100644 | |
--- a/views/Project.bones | |
+++ b/views/Project.bones | |
@@ -46,6 +46,7 @@ view.prototype.initialize = function() { | |
'exportList', | |
'statusOpen', | |
'statusClose', | |
+ 'colors', | |
'colorOpen', | |
'colorSave', | |
'colorClose', | |
@@ -149,7 +150,8 @@ view.prototype.makeStylesheet = function(model) { | |
tabMode: 'shift', | |
mode: { | |
name: 'carto', | |
- reference: window.abilities.carto | |
+ reference: window.abilities.carto, | |
+ onColor: this.colors | |
}, | |
onCursorActivity: function() { | |
model.set({'data': model.codemirror.getValue()}); | |
@@ -209,17 +212,7 @@ view.prototype.attach = function() { | |
$(this.map.controls.legend.element()).remove(); | |
} | |
- // Rescan stylesheets for colors, dedupe, sort by luminosity | |
- // and render swatches for each one. | |
- this.$('.colors').empty(); | |
- _(this.model.get('Stylesheet').pluck('data').join('\n') | |
- .match(/\#[A-Fa-f0-9]{6}\b|\#[A-Fa-f0-9]{3}\b|\b(rgb\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)|rgba\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*(0?\.)?\d+\s*\))/g) || [] | |
- ).chain() | |
- .uniq(true) | |
- .each(_(function(color) { | |
- var swatch = templates.ProjectSwatch({color:color}); | |
- this.$('.colors').append(swatch); | |
- }).bind(this)); | |
+ this.colors(); | |
}; | |
view.prototype.change = function() { | |
@@ -536,3 +529,22 @@ view.prototype.unload = function(ev) { | |
return false; | |
}; | |
+view.prototype.colorList = []; | |
+view.prototype.colors = function(color) { | |
+ if (color) { | |
+ this.colorList[color] = true; | |
+ } | |
+ // Rescan stylesheets for colors, dedupe, sort by luminosity | |
+ // and render swatches for each one. | |
+ this.$('.colors').empty(); | |
+ _(this.model.get('Stylesheet').pluck('data').join('\n') | |
+ .match(/\#[A-Fa-f0-9]{6}\b|\#[A-Fa-f0-9]{3}\b|\b(rgb\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)|rgba\s*\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*(0?\.)?\d+\s*\))/g) || [] | |
+ ).chain() | |
+ .uniq(true) | |
+ .each(_(function(color) { | |
+ if (color[0] != '#' || this.colorList[color]) { | |
+ var swatch = templates.ProjectSwatch({ color: color}); | |
+ this.$('.colors').append(swatch); | |
+ } | |
+ }).bind(this)); | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment