Skip to content

Commit

Permalink
Updated profile handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeche committed Nov 20, 2012
1 parent 94621eb commit f4c8cb5
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 30 deletions.
8 changes: 4 additions & 4 deletions CodaPlugin/EMCodaEditor.m
Expand Up @@ -60,7 +60,7 @@ - (NSString *)syntax {
}

- (NSString *)profileName {
return DEFAULT_PROFILE;
return nil;
}

- (NSRange)currentLineRange {
Expand All @@ -79,11 +79,11 @@ - (void) replaceContentWithValue:(NSString *)value from:(NSUInteger)start to:(NS
[self.tv beginUndoGrouping];

// extract tabstops and clean-up output
Emmet *zc = [Emmet sharedInstance];
Emmet *emmet = [Emmet sharedInstance];

id output = [zc.jsc evalFunction:@"objcExtractTabstopsOnInsert" withArguments:value, nil];
id output = [emmet.jsc evalFunction:@"objcExtractTabstopsOnInsert" withArguments:value, nil];

NSDictionary *tabstopData = [zc.jsc convertJSObject:output toNativeType:@"object"];
NSDictionary *tabstopData = [emmet.jsc convertJSObject:output toNativeType:@"object"];
value = [tabstopData valueForKey:@"text"];
[self.tv replaceCharactersInRange:NSMakeRange(start, end - start) withString:value];

Expand Down
7 changes: 1 addition & 6 deletions EspressoPlugin/EMEspressoEditor.m
Expand Up @@ -82,12 +82,7 @@ - (NSString *)syntax {
}

- (NSString *)profileName {
NSString *syntax = [self syntax];
if ([syntax isEqualToString:@"xml"] || [syntax isEqualToString:@"xsl"]) {
return @"xml";
}

return @"line";
return nil;
}

- (NSRange)currentLineRange {
Expand Down
4 changes: 2 additions & 2 deletions JSCocoa Delegate/JSCocoaDelegate.m
Expand Up @@ -41,8 +41,8 @@ - (id)evalFunction:(NSString *)funcName withArguments:(id)firstArg, ... {
}

// register all arguments in JS context
for (NSUInteger i = 0; i < [arguments count]; i++) {
[argNames addObject:[NSString stringWithFormat:@"__objcArg%ld", i]];
for (int i = 0; i < [arguments count]; i++) {
[argNames addObject:[NSString stringWithFormat:@"__objcArg%d", i]];
[ctx setObject:[arguments objectAtIndex:i] withName:[argNames lastObject]];
}

Expand Down
6 changes: 1 addition & 5 deletions TextMatePlugin/EMTextMateEditor.m
Expand Up @@ -196,11 +196,7 @@ - (NSString *)profileName {
return @"line";
}

if ([syntax isEqualToString:@"xml"] || [syntax isEqualToString:@"xsl"]) {
return @"xml";
}

return @"html";
return nil;
}

- (NSString *)selection {
Expand Down
2 changes: 1 addition & 1 deletion ZenCoding/NSTextView+EmmetEditor.m
Expand Up @@ -38,7 +38,7 @@ - (NSString *)syntax {
}

- (NSString *)profileName {
return DEFAULT_PROFILE;
return nil;
}

- (NSRange)currentLineRange {
Expand Down
95 changes: 84 additions & 11 deletions ZenCoding/emmet-app.js
Expand Up @@ -1218,7 +1218,7 @@ var emmet = (function(global) {
if (!abbr) return '';

syntax = syntax || defaultSyntax;
profile = profile || defaultProfile;
// profile = profile || defaultProfile;

var filters = r('filters');
var parser = r('abbreviationParser');
Expand All @@ -1231,10 +1231,10 @@ var emmet = (function(global) {
syntax: syntax,
contextNode: contextNode
});

var filtersList = filters.composeList(syntax, profile, data[1]);
filters.apply(outputTree, filtersList, profile);
return outputTree.toString();
// return this.require('utils').replaceVariables(outputTree.toString());
},

/**
Expand Down Expand Up @@ -2439,7 +2439,7 @@ emmet.exec(function(require, _) {
}

item.data('paste', null);
return !_.isUndefined(pastedContentObj);
return !!pastedContentObj;
});

if (!targets.length && options.pastedContent) {
Expand Down Expand Up @@ -4909,22 +4909,25 @@ emmet.define('profile', function(require, _) {
* @returns {Object}
*/
get: function(name, syntax) {
if (syntax && _.isString(name)) {
if (!name && syntax) {
// search in user resources first
var profile = require('resources').findItem(syntax, 'profile');
if (profile) {
name = profile;
}
}

if (!name)
if (!name) {
return profiles.plain;
}

if (name instanceof OutputProfile)
if (name instanceof OutputProfile) {
return name;
}

if (_.isString(name) && name.toLowerCase() in profiles)
if (_.isString(name) && name.toLowerCase() in profiles) {
return profiles[name.toLowerCase()];
}

return this.create(name);
},
Expand Down Expand Up @@ -4999,10 +5002,15 @@ emmet.define('editorUtils', function(require, _) {
* @param {String} profile
*/
outputInfo: function(editor, syntax, profile) {
// most of this code makes sense for Java/Rhino environment
// because string that comes from Java are not actually JS string
// but Java String object so the have to be explicitly converted
// to native string
profile = profile || editor.getProfileName();
return {
/** @memberOf outputInfo */
syntax: String(syntax || editor.getSyntax()),
profile: String(profile || editor.getProfileName()),
profile: profile ? String(profile) : null,
content: String(editor.getContent())
};
},
Expand Down Expand Up @@ -5250,6 +5258,70 @@ emmet.define('actionUtils', function(require, _) {
}

return false;
},

/**
* Common syntax detection method for editors that doesn’t provide any
* info about current syntax scope.
* @param {IEmmetEditor} editor Current editor
* @param {String} hint Any syntax hint that editor can provide
* for syntax detection. Default is 'html'
* @returns {String}
*/
detectSyntax: function(editor, hint) {
var caretPos = editor.getCaretPos();
var syntax = hint || 'html';

if (!require('resources').hasSyntax(syntax))
syntax = 'html';

if (syntax == 'html') {
// are we inside <style> tag?
var pair = require('html_matcher').getTags(editor.getContent(), caretPos);
if (pair && pair[0] && pair[0].type == 'tag' && pair[0].name.toLowerCase() == 'style') {
// check that we're actually inside the tag
if (pair[0].end <= caretPos && pair[1].start >= caretPos)
syntax = 'css';
}
}

if (syntax == 'html') {
// are we inside style attribute?
var tree = require('xmlEditTree').parseFromPosition(editor.getContent(), caretPos, true);
if (tree) {
var attr = tree.itemFromPosition(caretPos, true);
if (attr && attr.name().toLowerCase() == 'style') {
var range = attr.valueRange(true);
if (range.start <= caretPos && range.end >= caretPos)
syntax = 'css';
}
}
}

return syntax;
},

/**
* Common method for detecting output profile
* @param {IEmmetEditor} editor
* @returns {String}
*/
detectProfile: function(editor) {
switch(editor.getSyntax()) {
case 'xml':
case 'xsl':
return 'xml';
case 'html':
var profile = require('resources').getVariable('profile');
if (!profile) { // no forced profile, guess from content
// html or xhtml?
profile = editor.getContent().search(/<!DOCTYPE[^>]+XHTML/i) != -1 ? 'xhtml': 'html';
}

return profile;
}

return 'xhtml';
}
};
});/**
Expand Down Expand Up @@ -7920,7 +7992,7 @@ emmet.define('wrapWithAbbreviation', function(require, _) {
var utils = require('utils');

syntax = syntax || emmet.defaultSyntax();
profile = profile || emmet.defaultProfile();
profile = require('profile').get(profile, syntax);

require('tabStops').resetTabstopIndex();

Expand Down Expand Up @@ -12282,8 +12354,9 @@ emmet.define('bootstrap', function(require, _) {
this.loadProfiles(data.profiles);
}

if (data.syntaxprofiles) {
this.loadSyntaxProfiles(data.syntaxprofiles);
var profiles = data.syntaxProfiles || data.syntaxprofiles;
if (profiles) {
this.loadSyntaxProfiles(profiles);
}
},

Expand Down
3 changes: 2 additions & 1 deletion ZenCoding/objc-zeneditor-wrap.js
Expand Up @@ -154,7 +154,8 @@ var objcEmmetEditor = (function() {
* @return {String}
*/
getProfileName: function() {
return objcToString(ctx.profileName());
var profile = ctx.profileName();
return profile ? objcToString(profile) : null;
},

/**
Expand Down
6 changes: 6 additions & 0 deletions ZenCoding/snippets.json
Expand Up @@ -188,27 +188,31 @@
"bds:o": "border-style:outset;",
"bdw": "border-width:|;",
"bdt": "border-top:|;",
"bt": "border-top:|;",
"bdt+": "border-top:${1:1px} ${2:solid} ${3:#000};",
"bdt:n": "border-top:none;",
"bdtw": "border-top-width:|;",
"bdts": "border-top-style:|;",
"bdts:n": "border-top-style:none;",
"bdtc": "border-top-color:#${1:000};",
"bdr": "border-right:|;",
"br": "border-right:|;",
"bdr+": "border-right:${1:1px} ${2:solid} ${3:#000};",
"bdr:n": "border-right:none;",
"bdrw": "border-right-width:|;",
"bdrs": "border-right-style:|;",
"bdrs:n": "border-right-style:none;",
"bdrc": "border-right-color:#${1:000};",
"bdb": "border-bottom:|;",
"bb": "border-bottom:|;",
"bdb+": "border-bottom:${1:1px} ${2:solid} ${3:#000};",
"bdb:n": "border-bottom:none;",
"bdbw": "border-bottom-width:|;",
"bdbs": "border-bottom-style:|;",
"bdbs:n": "border-bottom-style:none;",
"bdbc": "border-bottom-color:#${1:000};",
"bdl": "border-left:|;",
"bl": "border-left:|;",
"bdl+": "border-left:${1:1px} ${2:solid} ${3:#000};",
"bdl:n": "border-left:none;",
"bdlw": "border-left-width:|;",
Expand Down Expand Up @@ -491,6 +495,7 @@

"html": {
"filters": "html",
"profile": "html",
"snippets": {
"c": "<!-- |${child} -->",
"cc:ie6": "<!--[if lte IE 6]>\n\t${child}|\n<![endif]-->",
Expand Down Expand Up @@ -640,6 +645,7 @@

"xsl": {
"extends": "html",
"profile": "xml",
"filters": "html, xsl",
"abbreviations": {
"tm": "<xsl:template match=\"\" mode=\"\">",
Expand Down

0 comments on commit f4c8cb5

Please sign in to comment.