LeinardoSmith/shorthand — pull request #5 by redmunds (2014-01-20 21:35:33+00:00)
Title: Implement first provider: margin

This implements the first shorthand provider.

I added `ShorthandManager` with these API calls:

```
// public API
registerShorthandProvider(shorthandPropertyName, provider)
getProviderForProperty(shorthandPropertyName)

// Utility functions
expandTRBLValues(vals)
collapseTRBLValues(vals)
findPropInDecList(propName, declList)
parseDeclarationList(declListText)
unparseDeclarationList(declList)
wsvToArray(str)
```

Providers must implement these API calls:

```
convertShorthandToLonghand(decl)
convertLonghandToShorthand(declList)
```

I just wanted to to get it going, so code probably needs some work. I added some of the jsDoc comments, but I'm sure I missed many.

The inline editor does all of the parsing so providers don't need to do any -- just handle the syntax tree. The LESS syntax tree format is kinda verbose -- definitely not necessary for "margin" property, but maybe required for more complicated ones.

Brackets supports unit test in extensions (unittests.js) in case you care to add unit tests.

TODO:
* Undo (Ctrl-Z) and many other editor commands don't work
* Needs keyboard shortcut for "Done"
* lib/convert.js is not used, so that can ber removed after it's converted to a shorthand provider

Error Cases:

What should happen if convert back to shorthand fails? Currently, changes are ignored. Another option would be to insert longhand in place of original shorthand. If that's implemented, the source will have to be indented to match other rules.

Let me know if you have any questions.