A brand-new version of DocRipper has been released to the wild. This will be the first release of several upcoming releases that will bring support for new file formats in DocRipper. The goal is to maintain a limited set of dependencies and where necessary only add dependencies that provide a high level of performance.
- .sketch files are now supported! All text content (text labels, artboard labels and layer labels) are returned as a concatenated string. I’ve kept the parsing simple to avoid breaking changes and conform to the spirit of DocRipper’s mission to simply grab text from files.
- Cleans up module namespacing internally
Parsing Sketch Files
Extracting text from .sketch files proved to be an interesting excercise and required a couple of levels of digging into this proprietary format:
- Sketch files are sqlite3 databases Thanks to this SO question, I was able to read .sketch files using Ruby’s sqlite3 adapter. Sketch files contain a single payload “blob” which requires additional parsing.
- Binary Plist The payload blob turns out to be binary plist which I was able to parse using CFPropertyList. The plist contains an array of objects that are parsed to build the sketch file. The array appears to contain flattened references with several objects (string, uuid, dictionary) sometimes describing a single “sketch” object. Finding text references was a matter of identifying the text objects in this array. I ultimately found that using a black list to remove non-text objects was the practical solution in this case. I could not identify a consistent “rule” or class identification for text labels in this object list. I hope to re-examine this approach in the future.
Sometimes you need to find the expected format of dates in your PostgreSQL database. You can find the database’s default style using your psql console:
#Log into the postgresql console
#connect to your database
#interact with your database
Run entire Rspec File
CMD + SHIFT + T
Run specific test or block (where cursor is selected)
CMD + SHIFT + R
Providing public and private design patterns in Angular.js
The concept of Encapsulation is an important design pattern in most object-oriented programming designs. Determining which properties and methods should be accessible is a nice forcing function because it forces the programmer to think about how his or her could will be consumed.
Encapsulation is typically achieved by defining local variables within the function object. These locals can only be referenced by other functions defined on the function object.
What about AngularJS?
I find myself thinking a lot about what should be exposed publicly in my view controllers. As a beginner, it’s easy to just attach your functions and variables to $scope (or this if using `controller as` syntax) and call it a day. But do you really need your view to have access to all of those functions? In most cases you don’t. Instead, assign these private functions or values to a local variable within your controller function.
I often define a function that initializes the default values within the controller.
We need some way to re-serialize this object’s keys to camelCase after a response is received. Similarly, requests made to the server should be translated to under_score like the server is expecting. Fortunately the Restangular library makes this quite easy to accomplish.
Restangular allows you to add response and/or request interceptors which allow you to modify your data before and after a $http request. Using the Humps library to camelize and deCamelize, it was simple to modify the requests and responses handled by Restangular. Simply add a config block and use the provided RestangularProvider to add a responseInterceptor and a requestInterceptor: