Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
Added comments and cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeger committed Mar 9, 2016
1 parent a12b9ad commit e0b7627
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
21 changes: 17 additions & 4 deletions Classy/Parser/CASStyler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@
#import "CASObjectClassDescriptor.h"
#import "CASStyleableItem.h"

@protocol CASStylerCacheDelegate <NSObject>
@class CASStyleNode;

/**
* Protocol caching the @c CASStyleNode's. Adds the possibility to cache the in-memory representation of Classy's CAS
* file, since parsing the file is slower than loading cached version.
*/
@protocol CASCacheProtocol <NSObject>
@optional
- (NSArray *)cachedStyleNodesFromPath:(NSString *)path withVariables:(NSDictionary *)variables;
- (void)cacheStyleNodes:(NSArray *)styleNodes fromPath:(NSString *)path variables:(NSDictionary *)variables;
/**
* Loads cached version of stylesheet located at @c path with @c variables
*/
- (NSArray <CASStyleNode *> *)cachedStyleNodesFromCASPath:(NSString *)path withVariables:(NSDictionary *)variables;

/**
* Stores the stylesheet in-memory representation loaded from @c path with @c variables
*/
- (void)cacheStyleNodes:(NSArray <CASStyleNode *> *)styleNodes fromPath:(NSString *)path variables:(NSDictionary *)variables;
@end


Expand All @@ -26,7 +39,7 @@
*/
+ (instancetype)defaultStyler;

@property (nonatomic, weak) id<CASStylerCacheDelegate> cacheDelegate;
@property (nonatomic, weak) id<CASCacheProtocol> cache;

@property (nonatomic, copy) NSDictionary *variables;

Expand Down
10 changes: 4 additions & 6 deletions Classy/Parser/CASStyler.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ - (void)setFilePath:(NSString *)filePath error:(NSError **)error {
NSArray *styleNodes = nil;
NSSet *importedFileNames = nil;

if ([self.cacheDelegate respondsToSelector:@selector(cachedStyleNodesFromPath:withVariables:)]) {
styleNodes = [self.cacheDelegate cachedStyleNodesFromPath:filePath withVariables:self.variables];
if ([self.cache respondsToSelector:@selector(cachedStyleNodesFromCASPath:withVariables:)]) {
styleNodes = [self.cache cachedStyleNodesFromCASPath:filePath withVariables:self.variables];
}

if (styleNodes != nil) {
Expand All @@ -186,12 +186,10 @@ - (void)setFilePath:(NSString *)filePath error:(NSError **)error {
}
return NSOrderedSame;
}];


if ([self.cacheDelegate respondsToSelector:@selector(cacheStyleNodes:fromPath:variables:)]) {
[self.cacheDelegate cacheStyleNodes:styleNodes fromPath:filePath variables:self.variables];
if ([self.cache respondsToSelector:@selector(cacheStyleNodes:fromPath:variables:)]) {
[self.cache cacheStyleNodes:styleNodes fromPath:filePath variables:self.variables];
}
styleNodes = [self.cacheDelegate cachedStyleNodesFromPath:filePath withVariables:self.variables];
}

if (self.watchFilePath) {
Expand Down

0 comments on commit e0b7627

Please sign in to comment.