├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── api_doc
└── html
│ ├── Classes
│ ├── HBDataContext.html
│ ├── HBExecutionContext.html
│ ├── HBHandlebars.html
│ ├── HBHelper.html
│ ├── HBHelperCallingInfo.html
│ ├── HBHelperMissingError.html
│ ├── HBHelperRegistry.html
│ ├── HBHelperUtils.html
│ ├── HBParseError.html
│ ├── HBPartial.html
│ ├── HBPartialMissingError.html
│ ├── HBPartialRegistry.html
│ └── HBTemplate.html
│ ├── Protocols
│ ├── HBExecutionContextDelegate.html
│ └── HBHandlebarsKVCValidation.html
│ ├── css
│ ├── styles.css
│ └── stylesPrint.css
│ ├── hierarchy.html
│ ├── img
│ ├── button_bar_background.png
│ ├── disclosure.png
│ ├── disclosure_open.png
│ ├── library_background.png
│ └── title_background.png
│ └── index.html
├── doc
├── ContextObjects.md
├── ControllingEscaping.md
├── Installation.md
├── LocalizingStrings.md
├── Release Notes.md
└── WritingHelpers.md
├── handlebars-objc.podspec
└── src
├── handlebars-objc.xcodeproj
├── .gitignore
├── project.pbxproj
├── project.xcworkspace
│ ├── .gitignore
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ ├── WorkspaceSettings.xcsettings
│ │ └── handlebars-objc.xccheckout
└── xcshareddata
│ └── xcschemes
│ ├── handlebars-objc-ios.xcscheme
│ └── handlebars-objc-osx.xcscheme
├── handlebars-objc
├── HBHandlebars.h
├── HBHandlebars.m
├── ast
│ ├── HBAst.h
│ ├── HBAstBlock.h
│ ├── HBAstBlock.m
│ ├── HBAstComment.h
│ ├── HBAstComment.m
│ ├── HBAstNode.h
│ ├── HBAstNode.m
│ ├── HBAstPartialTag.h
│ ├── HBAstPartialTag.m
│ ├── HBAstProgram.h
│ ├── HBAstProgram.m
│ ├── HBAstRawText.h
│ ├── HBAstRawText.m
│ ├── HBAstSimpleTag.h
│ ├── HBAstSimpleTag.m
│ ├── HBAstTag.h
│ ├── HBAstTag.m
│ └── expression
│ │ ├── HBAstContextualValue.h
│ │ ├── HBAstContextualValue.m
│ │ ├── HBAstExpression.h
│ │ ├── HBAstExpression.m
│ │ ├── HBAstKeyPathComponent.h
│ │ ├── HBAstKeyPathComponent.m
│ │ ├── HBAstNumber.h
│ │ ├── HBAstNumber.m
│ │ ├── HBAstParametersHash.h
│ │ ├── HBAstParametersHash.m
│ │ ├── HBAstString.h
│ │ ├── HBAstString.m
│ │ ├── HBAstValue.h
│ │ └── HBAstValue.m
├── astVisitors
│ ├── HBAstEvaluationVisitor.h
│ ├── HBAstEvaluationVisitor.m
│ ├── HBAstParserPostprocessingVisitor.h
│ ├── HBAstParserPostprocessingVisitor.m
│ ├── HBAstParserTestVisitor.h
│ ├── HBAstParserTestVisitor.m
│ ├── HBAstVisitor.h
│ └── HBAstVisitor.m
├── context
│ ├── HBContextRendering.h
│ ├── HBContextRendering.m
│ ├── HBContextStack.h
│ ├── HBContextStack.m
│ ├── HBContextState.h
│ ├── HBContextState.m
│ ├── HBDataContext.h
│ ├── HBDataContext.m
│ ├── HBHandlebarsKVCValidation.h
│ ├── HBObjectPropertyAccess.h
│ └── HBObjectPropertyAccess.m
├── en.lproj
│ └── InfoPlist.strings
├── errorHandling
│ ├── HBErrorHandling.h
│ ├── HBErrorHandling.m
│ └── HBErrorHandling_Private.h
├── handlebars-objc-Info.plist
├── handlebars-objc-Prefix.pch
├── handlebars-objc-ios-Prefix.pch
├── helpers
│ ├── HBBuiltinHelpersRegistry.h
│ ├── HBBuiltinHelpersRegistry.m
│ ├── HBEscapedString.h
│ ├── HBEscapedString.m
│ ├── HBEscapedString_Private.h
│ ├── HBHelper.h
│ ├── HBHelper.m
│ ├── HBHelperCallingInfo.h
│ ├── HBHelperCallingInfo.m
│ ├── HBHelperCallingInfo_Private.h
│ ├── HBHelperRegistry.h
│ ├── HBHelperRegistry.m
│ ├── HBHelperUtils.h
│ └── HBHelperUtils.m
├── parser
│ ├── HBParser.h
│ ├── HBParser.m
│ ├── handlebars-objc.lm
│ └── handlebars-objc.ym
├── partials
│ ├── HBPartial.h
│ ├── HBPartial.m
│ ├── HBPartialRegistry.h
│ ├── HBPartialRegistry.m
│ └── HBPartial_Private.h
└── runtime
│ ├── HBEscapingFunctions.h
│ ├── HBEscapingFunctions.m
│ ├── HBExecutionContext.h
│ ├── HBExecutionContext.m
│ ├── HBExecutionContextDelegate.h
│ ├── HBExecutionContext_Private.h
│ ├── HBTemplate.h
│ ├── HBTemplate.m
│ └── HBTemplate_Private.h
├── handlebars-objcTests
├── HBTestAccessToObjectProperties.m
├── HBTestBuiltinBlockHelpers.m
├── HBTestCase.h
├── HBTestCase.m
├── HBTestData.m
├── HBTestEscaping.m
├── HBTestExecutionContext.m
├── HBTestExtraHelpersLibrary.m
├── HBTestHelpers.m
├── HBTestParser.m
├── HBTestPartials.m
├── HBTestSimpleBlocks.m
├── HBTestSimpleTags.m
├── HBTestSubexpressions.m
├── HBTestWhitespaceControl.m
├── en.lproj
│ └── InfoPlist.strings
├── handlebars-objc-iosTests-Info.plist
└── handlebars-objcTests-Info.plist
├── non-unit-tests
└── test-embedding-in-projects
│ ├── Test OSX CocoaPods
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Pods
│ │ ├── Pods-ios-app-handlebars-objc.xcconfig
│ │ └── Pods-osx-app.xcconfig
│ ├── Test OSX CocoaPods.xcodeproj
│ │ ├── .gitignore
│ │ ├── project.pbxproj
│ │ └── project.xcworkspace
│ │ │ ├── .gitignore
│ │ │ └── contents.xcworkspacedata
│ ├── Test OSX CocoaPods.xcworkspace
│ │ ├── .gitignore
│ │ └── contents.xcworkspacedata
│ ├── Test OSX CocoaPods
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Base.lproj
│ │ │ └── MainMenu.xib
│ │ ├── Test OSX CocoaPods-Info.plist
│ │ ├── Test OSX CocoaPods-Prefix.pch
│ │ ├── en.lproj
│ │ │ ├── Credits.rtf
│ │ │ └── InfoPlist.strings
│ │ └── main.m
│ └── Test iOS Application With CocoaPods
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Images.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ └── LaunchImage.launchimage
│ │ │ └── Contents.json
│ │ ├── Test iOS Application With CocoaPods-Info.plist
│ │ ├── Test iOS Application With CocoaPods-Prefix.pch
│ │ ├── en.lproj
│ │ └── InfoPlist.strings
│ │ └── main.m
│ ├── Test OSX Embedding
│ ├── Test OSX Embedding.xcodeproj
│ │ ├── .gitignore
│ │ ├── project.pbxproj
│ │ └── project.xcworkspace
│ │ │ ├── .gitignore
│ │ │ └── contents.xcworkspacedata
│ └── Test OSX Embedding
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Base.lproj
│ │ └── MainMenu.xib
│ │ ├── Test OSX Embedding-Info.plist
│ │ ├── Test OSX Embedding-Prefix.pch
│ │ └── main.m
│ └── Test iOS Embedding
│ ├── Test iOS Embedding.xcodeproj
│ ├── .gitignore
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ ├── .gitignore
│ │ └── contents.xcworkspacedata
│ └── Test iOS Embedding
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── Test iOS Embedding-Info.plist
│ ├── Test iOS Embedding-Prefix.pch
│ └── main.m
└── utils
├── AppledocSettings.plist
├── build_binary_distribution.sh
├── convert-js-test.rb
├── copy_public_headers.sh
├── generate_api_doc.sh
├── generate_github_pages.sh
└── travis-tests.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | DerivedData
3 | binaries
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 | script: ./src/utils/travis-tests.sh
3 |
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Fotonauts
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/api_doc/html/css/stylesPrint.css:
--------------------------------------------------------------------------------
1 |
2 | header {
3 | display: none;
4 | }
5 |
6 | div.main-navigation, div.navigation-top {
7 | display: none;
8 | }
9 |
10 | div#overview_contents, div#contents.isShowingTOC, div#contents {
11 | overflow: visible;
12 | position: relative;
13 | top: 0px;
14 | border: none;
15 | left: 0;
16 | }
17 | #tocContainer.isShowingTOC {
18 | display: none;
19 | }
20 | nav {
21 | display: none;
22 | }
--------------------------------------------------------------------------------
/api_doc/html/hierarchy.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | handlebars-objc Hierarchy
6 |
7 |
8 |
9 |
10 |
11 |
22 |
23 |
24 |
27 |
32 |
33 |
34 |
35 |
Class Hierarchy
36 |
37 |
38 |
39 | - NSError
40 |
49 |
50 |
51 | - NSObject
52 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
Protocol References
86 |
93 |
94 |
95 |
96 |
97 |
98 |
101 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/api_doc/html/img/button_bar_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bertrand/handlebars-objc/e98bb1234c95ff7a88e6fac1c3d1df7f310ce262/api_doc/html/img/button_bar_background.png
--------------------------------------------------------------------------------
/api_doc/html/img/disclosure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bertrand/handlebars-objc/e98bb1234c95ff7a88e6fac1c3d1df7f310ce262/api_doc/html/img/disclosure.png
--------------------------------------------------------------------------------
/api_doc/html/img/disclosure_open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bertrand/handlebars-objc/e98bb1234c95ff7a88e6fac1c3d1df7f310ce262/api_doc/html/img/disclosure_open.png
--------------------------------------------------------------------------------
/api_doc/html/img/library_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bertrand/handlebars-objc/e98bb1234c95ff7a88e6fac1c3d1df7f310ce262/api_doc/html/img/library_background.png
--------------------------------------------------------------------------------
/api_doc/html/img/title_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bertrand/handlebars-objc/e98bb1234c95ff7a88e6fac1c3d1df7f310ce262/api_doc/html/img/title_background.png
--------------------------------------------------------------------------------
/api_doc/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | handlebars-objc Reference
6 |
7 |
8 |
9 |
10 |
11 |
22 |
23 |
24 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
Class References
40 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
Protocol References
76 |
83 |
84 |
85 |
86 |
87 |
88 |
91 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/doc/Installation.md:
--------------------------------------------------------------------------------
1 | # Installation #
2 |
3 |
4 | There are 3 options to use handlebars-objc in your project.
5 |
6 | Let's start with the easiest one.
7 |
8 |
9 | ## Option 1: CocoaPods ##
10 |
11 | CocoaPods is a very clever packaging system for Objective-C libraries and is by far the cleanest way to include external development frameworks in your Cocoa or UIKit projects.
12 |
13 | Please read the instructions at http://cocoapods.org to get started.
14 |
15 | To use handlebars-objc in your project, simply add the handlebars-objc pod to your Podfile:
16 |
17 | ```
18 | pod 'handlebars-objc', '~> 1.0.0'
19 | ```
20 |
21 |
22 | ## Option 2: Binary distribution ##
23 |
24 | Go to https://github.com/fotonauts/handlebars-objc/releases and download the latest release. Then, uncompress the zip file. The resulting folder contains:
25 | - an OS X framework in the osx folder
26 | - an iOS framework in the ios folder
27 | - API documentation in the api_doc folder
28 | - Higher level documentation in the doc folder
29 |
30 | To use the framework, copy the version you need (ios or osx) into your project and add it to the frameworks your project links against.
31 |
32 |
33 | ## Option 3: Include handlebars-objc as a subproject in Xcode ##
34 |
35 | - copy the sources of handlebars-objc into your project directory (or best, use a git submodule)
36 | - add handlebars-objc.xcodeproj to your project (no need to add all of the sources to your project)
37 |
38 | If your project targets iOS:
39 |
40 | - modify your project build settings and add "$(TEMP_ROOT)/Headers" to your header search path (without the quotes).
41 | - add handlebars-objc-ios as a target dependency to your target
42 | - link against libhandlebars-objc-ios.a
43 |
44 | If your project targets OS X:
45 |
46 | - add handlebars-objc-osx as a target dependency to your target
47 | - link against Handlebars.framework
48 |
49 |
--------------------------------------------------------------------------------
/doc/LocalizingStrings.md:
--------------------------------------------------------------------------------
1 | # Localizing Strings #
2 |
3 | ## Localization in templates ##
4 |
5 | Within templates, strings can be localized using the 'localize' helper.
6 | This helper translates a string into another.
7 |
8 | For instance, the template
9 |
10 | hello is '{{localize "hello"}}' in current locale
11 |
12 | Would render as "hello is 'bonjour' in current locale".
13 | (if locale is french)
14 |
15 | Of course, in this case, the translation of 'hello' into 'bonjour' is not known to handlebars-objc and has to be provided by the client application.
16 |
17 | ## Providing localization from the client application ##
18 |
19 | As seen above, the client application is responsible for providing the actual mapping between untranslated and translated strings. This section documents the various ways an application can provide string translations.
20 |
21 | ### Using standard MacOS and iOS localization process ###
22 |
23 | The simplest way to provide translations to your templates is to add them to your application localization strings.
24 | When looking for a translation, if none is provided by other mechanisms, handlebars-objc falls back to standard translation mechanism.
25 |
26 | Please read [Offical Apple Documentation](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/Articles/StringsFiles.html) for detailed instructions on how to provide localization strings to your application.
27 |
28 | ### Using custom translation mappings ###
29 |
30 | If MacOS and iOS localization strings are not enough, handlebars-objc provides delegation APIs you can use to provide your own translations.
31 |
32 | Let's first create a simple delegate:
33 |
34 | @interface SimpleLocalizationDelegate : NSObject
35 |
36 | - (NSString*) localizedString:(NSString*)string forExecutionContext:(HBExecutionContext*)executionContext;
37 |
38 | @end
39 |
40 | @implementation SimpleLocalizationDelegate
41 |
42 | - (NSString*) localizedString:(NSString*)string forExecutionContext:(HBExecutionContext*)executionContext
43 | {
44 | // if string to translate is "handlebars", return french translation
45 | if ([string isEqual:@"handlebars"]) return @"guidon";
46 | // otherwise, provide no translation at all. Handlebars-objc will then fallback to other mechanisms
47 | else return nil;
48 | }
49 |
50 | @end
51 |
52 | This delegate implements the -localizedString:forExecutionContext: method to return the French translation for the world "handlebars".
53 |
54 | Of course, a real world example would return the translation in current locale, and not always in French.
55 |
56 | Now let's see how we can use this delegate class when rendering a template:
57 |
58 | // create a new execution context
59 | HBExecutionContext* executionContext = [[HBExecutionContext new] autorelease];
60 |
61 | // set its delegate (will provide localization of "handlebars" string)
62 | executionContext.delegate = [[SimpleLocalizationDelegate new] autorelease];
63 |
64 | // render template
65 | HBTemplate* template = [executionContext templateWithString:@"hello {{localize 'handlebars'}}!"];
66 |
67 | NSError* error = nil;
68 | NSString* evaluation = [template renderWithContext:nil error:&error];
69 |
70 | // evaluation now contains "hello guidon!"
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/doc/Release Notes.md:
--------------------------------------------------------------------------------
1 | # Release Notes #
2 |
3 | ## v1.1 ##
4 |
5 | ##### Handlebars.js 2.0 compatibility #####
6 | - @index, @first and @last data in #each helper
7 | - Subexpressions in helpers using parenthesized sub helpers invocation
8 | - Whitespace control in tags via {{~ ... ~}}
9 | - Raw block helpers via {{{{ ... }}}}
10 | - Access to upper-level data contexts via @../
11 | - Hash parameters in partial tag
12 | - Access to root context via @root data
13 | - Decimal litterals
14 | - includeZero in #if and #unless helpers controls the boolean value of 0
15 |
16 | ##### Handlebars.objc specifics #####
17 | - Support for custom escaping modes
18 | - Support for string localization
19 | - Travis CI support
20 | - [#4](https://github.com/fotonauts/handlebars-objc/pull/4) Fix a memory leak ([@randomsequence](https://github.com/randomsequence))
21 |
22 | ## v1.0.1 ##
23 |
24 | - Fix public headers in OS X framework
25 | - Fix installation documentation (including project sources)
26 |
27 |
28 | ## v1.0.0 ##
29 |
30 | - Initial release
31 |
32 |
--------------------------------------------------------------------------------
/handlebars-objc.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 |
3 | s.name = "handlebars-objc"
4 | s.version = "1.4.4"
5 | s.summary = "handlebars-objc is an implementation of Handlebars.js for Objective-C"
6 | s.homepage = "https://github.com/Bertrand/handlebars-objc"
7 | s.license = { :type => 'MIT', :file => 'LICENSE' }
8 | s.author = { "Bertrand Guiheneuf" => "guiheneuf@gmail.com" }
9 | s.ios.deployment_target = '6.0'
10 | s.osx.deployment_target = '10.8'
11 | s.source = { :git => "https://github.com/Bertrand/handlebars-objc.git", :tag => "v#{s.version}" }
12 | s.source_files = 'src/handlebars-objc', 'src/handlebars-objc/**/*.{h,m,ym,lm}'
13 | s.public_header_files = %w(HBHandlebars.h runtime/HBTemplate.h runtime/HBExecutionContext.h runtime/HBExecutionContextDelegate.h runtime/HBEscapingFunctions.h context/HBDataContext.h context/HBHandlebarsKVCValidation.h helpers/HBHelper.h helpers/HBHelperRegistry.h helpers/HBHelperCallingInfo.h helpers/HBHelperUtils.h helpers/HBEscapedString.h partials/HBPartial.h partials/HBPartialRegistry.h errorHandling/HBErrorHandling.h).map{|f| "src/handlebars-objc/#{f}"}
14 | s.header_dir = "HBHandlebars"
15 | s.requires_arc = false
16 | s.pod_target_xcconfig = { 'OTHER_CFLAGS' => '-fno-objc-arc' }
17 |
18 | end
19 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/project.xcworkspace/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/project.xcworkspace/xcshareddata/handlebars-objc.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | F5D6E5B5-7ED1-4BE4-861A-D3AD338F15CB
9 | IDESourceControlProjectName
10 | handlebars-objc
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | F8F2BFC7-1DB5-4C42-85C7-8209F44C731E
14 | ssh://github.com/fotonauts/handlebars-objc.git
15 |
16 | IDESourceControlProjectPath
17 | handlebars-objc.xcodeproj/project.xcworkspace
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | F8F2BFC7-1DB5-4C42-85C7-8209F44C731E
21 | ../..
22 |
23 | IDESourceControlProjectURL
24 | ssh://github.com/fotonauts/handlebars-objc.git
25 | IDESourceControlProjectVersion
26 | 110
27 | IDESourceControlProjectWCCIdentifier
28 | F8F2BFC7-1DB5-4C42-85C7-8209F44C731E
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | F8F2BFC7-1DB5-4C42-85C7-8209F44C731E
36 | IDESourceControlWCCName
37 | handlebars-objc
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/xcshareddata/xcschemes/handlebars-objc-ios.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
52 |
53 |
54 |
55 |
61 |
62 |
64 |
65 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/handlebars-objc.xcodeproj/xcshareddata/xcschemes/handlebars-objc-osx.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
52 |
53 |
54 |
55 |
61 |
62 |
64 |
65 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/handlebars-objc/HBHandlebars.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBHandlebars.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/1/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 |
29 | #import "HBHandlebars.h"
30 |
31 | #import "HBAst.h"
32 | #import "HBAstEvaluationVisitor.h"
33 | #import "HBParser.h"
34 | #import "HBTemplate.h"
35 | #import "HBHelper.h"
36 |
37 |
38 | static HBLoggerBlock _loggerBlock = nil;
39 |
40 | @implementation HBHandlebars
41 |
42 | + (NSString*)renderTemplateString:(NSString*)template withContext:(id)context error:(NSError**)error
43 | {
44 | return [self renderTemplateString:template withContext:context withHelperBlocks:nil withPartialStrings:nil error:error];
45 | }
46 |
47 | + (NSString*)renderTemplateString:(NSString*)template withContext:(id)context withHelperBlocks:(NSDictionary*)helperBlocks error:(NSError**)error;
48 | {
49 | return [self renderTemplateString:template withContext:context withHelperBlocks:helperBlocks withPartialStrings:nil error:error];
50 | }
51 |
52 | + (NSString*)renderTemplateString:(NSString*)template withContext:(id)context withHelperBlocks:(NSDictionary*)helperBlocks withPartialStrings:(NSDictionary*)partials error:(NSError**)error
53 | {
54 | HBTemplate* hbTemplate = [[HBTemplate alloc] initWithString:template];
55 | if (helperBlocks) [hbTemplate.helpers registerHelperBlocks:helperBlocks];
56 | if (partials) [hbTemplate.partials registerPartialStrings:partials];
57 |
58 | NSString* renderedString = [hbTemplate renderWithContext:context error:error];
59 |
60 | [hbTemplate release];
61 | return renderedString;
62 | }
63 |
64 | #pragma mark -
65 | #pragma mark Partials
66 |
67 | + (void) registerHelperBlock:(HBHelperBlock)block forName:(NSString*)helperName
68 | {
69 | [[HBExecutionContext globalExecutionContext].helpers registerHelperBlock:block forName:helperName];
70 | }
71 |
72 | + (void) unregisterHelperForName:(NSString*)helperName
73 | {
74 | [[HBExecutionContext globalExecutionContext].helpers removeHelperForName:helperName];
75 | }
76 |
77 | + (void) unregisterAllHelpers
78 | {
79 | [[HBExecutionContext globalExecutionContext].helpers removeAllHelpers];
80 | }
81 |
82 | #pragma mark -
83 | #pragma mark Partials
84 |
85 | + (void) registerPartialString:(NSString*)partialString forName:(NSString*)partialName
86 | {
87 | [[HBExecutionContext globalExecutionContext].partials registerPartialString:partialString forName:partialName];
88 | }
89 |
90 | + (void) unregisterPartialForName:(NSString*)partialName
91 | {
92 | [[HBExecutionContext globalExecutionContext].partials unregisterPartialForName:partialName];
93 | }
94 |
95 | + (void) unregisterAllPartials
96 | {
97 | [[HBExecutionContext globalExecutionContext].partials unregisterAllPartials];
98 | }
99 |
100 | #pragma mark -
101 | #pragma mark Logger
102 |
103 | + (void) setLoggerBlock:(HBLoggerBlock)loggerBlock
104 | {
105 | if (_loggerBlock != loggerBlock) {
106 | [_loggerBlock release];
107 | _loggerBlock = [loggerBlock retain];
108 | }
109 | }
110 |
111 | + (void) log:(NSInteger)level object:(id)object
112 | {
113 | if (_loggerBlock) {
114 | _loggerBlock(level, object);
115 | } else {
116 | NSLog(@"%@", [object description]);
117 | }
118 | }
119 |
120 | @end
121 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAst.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAst.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/26/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | // High-level nodes
29 |
30 | #import "HBAstBlock.h"
31 | #import "HBAstNode.h"
32 | #import "HBAstComment.h"
33 | #import "HBAstPartialTag.h"
34 | #import "HBAstProgram.h"
35 | #import "HBAstRawText.h"
36 | #import "HBAstSimpleTag.h"
37 | #import "HBAstTag.h"
38 |
39 | // Expressions
40 |
41 | #import "HBAstContextualValue.h"
42 | #import "HBAstExpression.h"
43 | #import "HBAstKeyPathComponent.h"
44 | #import "HBAstNumber.h"
45 | #import "HBAstString.h"
46 | #import "HBAstValue.h"
47 |
48 | // Parse internals
49 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstBlock.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstBlockTag.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 | #import "HBAstProgram.h"
30 |
31 | @class HBAstTag;
32 | @class HBAstExpression;
33 |
34 | @interface HBAstBlock : HBAstNode
35 |
36 | @property (retain, nonatomic) HBAstTag* openTag;
37 | @property (retain, nonatomic) HBAstTag* elseTag;
38 | @property (retain, nonatomic) HBAstTag* closeTag;
39 |
40 | @property (readonly, nonatomic) HBAstExpression* expression; // computed
41 |
42 | @property (retain, nonatomic) NSMutableArray* statements;
43 | @property (retain, nonatomic) NSMutableArray* inverseStatements;
44 |
45 | @property BOOL invertedBlock;
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstBlock.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstBlockTag.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 |
29 | #import "HBAstBlock.h"
30 | #import "HBAstVisitor.h"
31 |
32 | @implementation HBAstBlock
33 |
34 | - (HBAstExpression*) expression
35 | {
36 | return self.openTag ? self.openTag.expression : nil;
37 | }
38 |
39 | - (id) accept:(HBAstVisitor*)visitor
40 | {
41 | return [visitor visitBlock:self];
42 | }
43 |
44 | - (void) dealloc
45 | {
46 | self.openTag = nil;
47 | self.elseTag = nil;
48 | self.closeTag = nil;
49 |
50 | self.statements = nil;
51 | self.inverseStatements = nil;
52 |
53 | [super dealloc];
54 | }
55 |
56 | @end
57 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstComment.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstComment.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 |
30 | @interface HBAstComment : HBAstNode
31 |
32 | @property (retain, nonatomic) NSString* litteralValue;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstComment.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstComment.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstComment.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstComment
32 |
33 | - (id) accept:(HBAstVisitor*)visitor
34 | {
35 | return [visitor visitComment:self];
36 | }
37 |
38 | - (void) dealloc
39 | {
40 | self.litteralValue = nil;
41 | [super dealloc];
42 | }
43 | @end
44 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstNode.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstNode.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/25/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @class HBAstVisitor;
31 |
32 | @interface HBAstNode : NSObject
33 |
34 | - (NSString*)formalDump;
35 |
36 | // help visitors be fast
37 |
38 | - (id) accept:(HBAstVisitor*)visitor;
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstNode.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstNode.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/25/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstNode
32 |
33 | - (NSString*)formalDump
34 | {
35 | return nil;
36 | }
37 |
38 | - (id) accept:(HBAstVisitor*)visitor
39 | {
40 | NSAssert(false, @"abstract method. Must be overloaded by concrete subclasses");
41 | return nil;
42 | }
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstPartialTag.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstPartial.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstTag.h"
29 | #import "HBAstValue.h"
30 | #import "HBAstContextualValue.h"
31 | #import "HBAstParametersHash.h"
32 |
33 | @interface HBAstPartialTag : HBAstTag
34 |
35 | @property (retain, nonatomic) HBAstValue* partialName;
36 | @property (retain, nonatomic) HBAstContextualValue* context;
37 | @property (retain, nonatomic) HBAstParametersHash* namedParameters;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstPartialTag.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstPartial.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstPartialTag.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstPartialTag
32 |
33 | - (id) accept:(HBAstVisitor*)visitor
34 | {
35 | return [visitor visitPartialTag:self];
36 | }
37 |
38 | - (void) dealloc
39 | {
40 | self.partialName = nil;
41 | self.context = nil;
42 | self.namedParameters = nil;
43 |
44 | [super dealloc];
45 | }
46 | @end
47 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstProgram.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstProgram.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/25/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 |
30 | @interface HBAstProgram : HBAstNode
31 |
32 | @property (strong, nonatomic) NSArray* /* HBAstStatement */ statements;
33 | @property (retain, nonatomic) NSError* parseError;
34 |
35 | - (NSString*)formalDump;
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstProgram.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstProgram.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/25/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstProgram.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstProgram
32 |
33 | - (NSString*)formalDump
34 | {
35 | return @"";
36 | }
37 |
38 | - (id) accept:(HBAstVisitor*)visitor
39 | {
40 | return [visitor visitProgram:self];
41 | }
42 |
43 | - (void) dealloc
44 | {
45 | self.statements = nil;
46 | self.parseError = nil;
47 | [super dealloc];
48 | }
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstRawText.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstRawText.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 |
30 | @interface HBAstRawText : HBAstNode
31 |
32 | @property (retain, nonatomic) NSString* litteralValue;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstRawText.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstRawText.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstRawText.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstRawText
32 |
33 | - (id) accept:(HBAstVisitor*)visitor
34 | {
35 | return [visitor visitRawText:self];
36 | }
37 |
38 | - (void) dealloc
39 | {
40 | self.litteralValue = nil;
41 | [super dealloc];
42 | }
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstSimpleTag.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstSimpleTag.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstTag.h"
29 |
30 | @interface HBAstSimpleTag : HBAstTag
31 |
32 | @property BOOL escape;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstSimpleTag.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstSimpleTag.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstSimpleTag.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstSimpleTag
32 |
33 | - (id) accept:(HBAstVisitor*)visitor
34 | {
35 | return [visitor visitSimpleTag:self];
36 | }
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstTag.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstTag.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 | #import "HBAstExpression.h"
30 |
31 | @interface HBAstTag : HBAstNode
32 |
33 | @property (retain, nonatomic) HBAstExpression* expression;
34 | @property (assign, nonatomic) BOOL left_wsc;
35 | @property (assign, nonatomic) BOOL right_wsc;
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/HBAstTag.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstTag.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstTag.h"
29 |
30 | @implementation HBAstTag
31 |
32 |
33 | - (void) dealloc
34 | {
35 | self.expression = nil;
36 | [super dealloc];
37 | }
38 | @end
39 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstContextualValue.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstContextualValue.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstValue.h"
29 |
30 | @interface HBAstContextualValue : HBAstValue
31 |
32 | @property (retain, nonatomic) NSMutableArray* /* HBAstKeyPathComponent */ keyPath;
33 |
34 | @property (readonly) BOOL hasSimpleIdentifier;
35 | @property (readonly) BOOL hasPathIdentifier;
36 |
37 | @property BOOL isDataValue;
38 |
39 |
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstContextualValue.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstContextualValue.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstContextualValue.h"
29 | #import "HBAstKeyPathComponent.h"
30 | #import "HBAstVisitor.h"
31 |
32 | @implementation HBAstContextualValue
33 |
34 | - (BOOL)hasSimpleIdentifier
35 | {
36 | return (self.keyPath) && (self.keyPath.count == 1);
37 | }
38 |
39 | - (BOOL)hasPathIdentifier
40 | {
41 | return (self.keyPath) && (self.keyPath.count > 1);
42 | }
43 |
44 | - (NSString*) sourceRepresentation
45 | {
46 | NSMutableString* result = [NSMutableString string];
47 | for (HBAstKeyPathComponent* pathComponent in self.keyPath) {
48 | [result appendString:[pathComponent sourceRepresentation]];
49 | }
50 | return result;
51 | }
52 |
53 | - (id) accept:(HBAstVisitor*)visitor
54 | {
55 | return [visitor visitContextualValue:self];
56 | }
57 |
58 | - (void) dealloc
59 | {
60 | self.keyPath = nil;
61 | [super dealloc];
62 | }
63 |
64 | @end
65 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstExpression.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstExpression.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstValue.h"
29 | #import "HBAstContextualValue.h"
30 | #import "HBAstParametersHash.h"
31 |
32 | @interface HBAstExpression : HBAstValue
33 |
34 | @property (retain, nonatomic) HBAstContextualValue* mainValue;
35 | @property (retain, nonatomic) NSMutableArray* /* HBAstValue */ positionalParameters;
36 | @property (retain, nonatomic) HBAstParametersHash* namedParameters;
37 |
38 | - (void) addPositionalParameter:(HBAstValue*)parameter;
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstExpression.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstExpression.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstExpression.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstExpression
32 |
33 | - (void) addPositionalParameter:(HBAstValue*)parameter
34 | {
35 | if (self.positionalParameters == nil) self.positionalParameters = [NSMutableArray array];
36 | [self.positionalParameters addObject:parameter];
37 | }
38 |
39 | - (id) accept:(HBAstVisitor*)visitor
40 | {
41 | return [visitor visitExpression:self];
42 | }
43 |
44 | - (void) dealloc
45 | {
46 | self.mainValue = nil;
47 | self.positionalParameters = nil;
48 | self.namedParameters = nil;
49 |
50 | [super dealloc];
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstKeyPathComponent.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstIdentifier.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/26/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 |
30 | @interface HBAstKeyPathComponent : HBAstNode
31 |
32 | @property (retain, nonatomic) NSString* key;
33 | @property (retain, nonatomic) NSString* leadingSeparator;
34 | @property (readonly, nonatomic) NSString* sourceRepresentation;
35 |
36 | - (NSString*)formalDump;
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstKeyPathComponent.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstIdentifier.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/26/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstKeyPathComponent.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstKeyPathComponent
32 |
33 | - (NSString*)formalDump
34 | {
35 | return @"";
36 | }
37 |
38 | - (NSString*) sourceRepresentation
39 | {
40 | return [NSString stringWithFormat:@"%@%@", self.leadingSeparator ? self.leadingSeparator : @"", self.key];
41 | }
42 |
43 | - (id) accept:(HBAstVisitor*)visitor
44 | {
45 | return [visitor visitKeyPathComponent:self];
46 | }
47 |
48 | - (void) dealloc
49 | {
50 | self.leadingSeparator = nil;
51 | self.key = nil;
52 | [super dealloc];
53 | }
54 | @end
55 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstNumber.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstNumber.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstValue.h"
29 |
30 |
31 | //typedef struct HBParserIntegerValue HBParserIntegerValue;
32 | //struct HBParserIntegerValue {
33 | // int value;
34 | // NSString* source;
35 | //};
36 |
37 | @interface HBAstNumber : HBAstValue
38 |
39 | @property (retain, nonatomic) NSNumber* litteralValue;
40 | @property BOOL isBoolean;
41 | @property (retain, readwrite, nonatomic) NSString* sourceRepresentation;
42 |
43 | @end
44 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstNumber.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstNumber.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNumber.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstNumber
32 |
33 | // we need to synthetise the property manually to override superclass readonly version
34 | @synthesize sourceRepresentation;
35 |
36 | - (id) accept:(HBAstVisitor*)visitor
37 | {
38 | return [visitor visitNumber:self];
39 | }
40 |
41 | - (void) dealloc
42 | {
43 | self.litteralValue = nil;
44 | self.sourceRepresentation = nil;
45 | [super dealloc];
46 | }
47 | @end
48 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstParametersHash.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstParametersHash.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 3/24/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "HBAstNode.h"
10 | #import "HBAstValue.h"
11 |
12 | @interface HBAstParametersHash : HBAstNode
13 |
14 | @property (readonly, nonatomic) NSUInteger count;
15 | @property (retain, nonatomic) NSMutableDictionary* /* (NSString -> HBAstValue) */namedParameters;
16 | @property (retain, nonatomic) NSMutableArray* /* (NSString) */ orderedNamedParameterNames;
17 |
18 | - (void) appendParameter:(HBAstValue*)parameter forKey:(NSString*)key;
19 | - (void) appendNamedParameters:(NSDictionary*)namedParameters;
20 |
21 | // objc subscripting
22 | - (id)objectForKeyedSubscript:(id)key;
23 | // fast enumeration
24 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstParametersHash.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstParametersHash.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 3/24/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "HBAstParametersHash.h"
10 | #import "HBAstVisitor.h"
11 |
12 | @implementation HBAstParametersHash
13 |
14 | - (NSUInteger) count
15 | {
16 | return self.orderedNamedParameterNames.count;
17 | }
18 |
19 | - (void) appendParameter:(HBAstValue*)parameter forKey:(NSString*)key
20 | {
21 | if (self.namedParameters == nil) self.namedParameters = [NSMutableDictionary dictionary];
22 | if (self.orderedNamedParameterNames == nil) self.orderedNamedParameterNames = [NSMutableArray array];
23 | self.namedParameters[key] = parameter;
24 | [self.orderedNamedParameterNames addObject:key];
25 | }
26 |
27 | - (void) appendNamedParameters:(NSDictionary*)namedParameters
28 | {
29 | for (NSString* name in namedParameters) {
30 | [self appendParameter:namedParameters[name] forKey:name];
31 | }
32 | }
33 |
34 | // objc litteral compatibility
35 |
36 | - (id) objectForKeyedSubscript:(id)key
37 | {
38 | return [self.namedParameters objectForKey:key];
39 | }
40 |
41 | // fast enumeration
42 |
43 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
44 | {
45 | return [self.orderedNamedParameterNames countByEnumeratingWithState:state objects:stackbuf count:len];
46 | }
47 |
48 | // visitor protocol
49 |
50 | - (id) accept:(HBAstVisitor*)visitor
51 | {
52 | return [visitor visitParametersHash:self];
53 | }
54 |
55 | - (void) dealloc
56 | {
57 | self.namedParameters = nil;
58 | self.orderedNamedParameterNames = nil;
59 |
60 | [super dealloc];
61 | }
62 |
63 | @end
64 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstString.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstString.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstValue.h"
29 |
30 | @interface HBAstString : HBAstValue
31 |
32 | @property (retain, nonatomic) NSString* litteralValue;
33 | @property (retain, readwrite, nonatomic) NSString* sourceRepresentation;
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstString.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstString.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstString.h"
29 | #import "HBAstVisitor.h"
30 |
31 | @implementation HBAstString
32 |
33 | // we need to synthetise the property manually to override superclass readonly version
34 | @synthesize sourceRepresentation;
35 |
36 | - (id) accept:(HBAstVisitor*)visitor
37 | {
38 | return [visitor visitString:self];
39 | }
40 |
41 | - (void) dealloc
42 | {
43 | self.litteralValue = nil;
44 | self.sourceRepresentation = nil;
45 | [super dealloc];
46 | }
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstValue.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstValue.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstNode.h"
29 |
30 | @interface HBAstValue : HBAstNode
31 |
32 | @property (readonly, nonatomic) NSString* sourceRepresentation;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/src/handlebars-objc/ast/expression/HBAstValue.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstValue.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/27/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstValue.h"
29 | #import "HBAstVisitor.h"
30 | #import "HBAstVisitor.h"
31 |
32 | @implementation HBAstValue
33 |
34 | - (id) accept:(HBAstVisitor*)visitor
35 | {
36 | return [visitor visitValue:self];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/src/handlebars-objc/astVisitors/HBAstEvaluationVisitor.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstEvaluationVisitor.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/30/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstVisitor.h"
29 |
30 | @class HBHelperRegistry;
31 | @class HBTemplate;
32 |
33 | @interface HBAstEvaluationVisitor : HBAstVisitor
34 |
35 | @property (retain, nonatomic) HBTemplate* template;
36 | @property (retain, nonatomic) NSError* error;
37 |
38 | - (id) initWithTemplate:(HBTemplate*)template;
39 |
40 | - (NSString*) evaluateWithContext:(id)context;
41 |
42 | // escaping
43 |
44 | - (void) pushEscapingMode:(NSString*)mode;
45 | - (void) popEscapingMode;
46 | - (NSString*) currentEscapingMode;
47 | - (NSString*) escapeStringAccordingToCurrentMode:(NSString*)rawString;
48 | @end
49 |
--------------------------------------------------------------------------------
/src/handlebars-objc/astVisitors/HBAstParserPostprocessingVisitor.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstParserPostprocessingVisitor.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 3/23/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 | // The MIT License
9 | //
10 | // Permission is hereby granted, free of charge, to any person obtaining a copy
11 | // of this software and associated documentation files (the "Software"), to deal
12 | // in the Software without restriction, including without limitation the rights
13 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | // copies of the Software, and to permit persons to whom the Software is
15 | // furnished to do so, subject to the following conditions:
16 | //
17 | // The above copyright notice and this permission notice shall be included in
18 | // all copies or substantial portions of the Software.
19 | //
20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 | // THE SOFTWARE.
27 | //
28 |
29 | #import "HBAstVisitor.h"
30 |
31 | @interface HBAstParserPostprocessingVisitor : HBAstVisitor
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/src/handlebars-objc/astVisitors/HBAstParserTestVisitor.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstParserTestVisitor.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstVisitor.h"
29 |
30 | @interface HBAstParserTestVisitor : HBAstVisitor
31 |
32 | - (NSString*) testStringRepresentation;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/src/handlebars-objc/astVisitors/HBAstVisitor.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstVisitor.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | #import "HBAst.h"
31 |
32 | @interface HBAstVisitor : NSObject
33 |
34 | @property (retain, nonatomic) HBAstNode* rootNode;
35 |
36 | // designated initializer
37 |
38 | - (id) initWithRootAstNode:(HBAstNode*)rootNode;
39 |
40 | // visiting a node
41 |
42 | - (id) visitNode:(HBAstNode*)node;
43 |
44 |
45 | // -- Methods that must be implemented by concrete subclasses --
46 |
47 |
48 | // High-level nodes
49 |
50 | - (id) visitBlock:(HBAstBlock*)node;
51 | - (id) visitPartialTag:(HBAstPartialTag*)node;
52 | - (id) visitComment:(HBAstComment*)node;
53 | - (id) visitProgram:(HBAstProgram*)node;
54 | - (id) visitRawText:(HBAstRawText*)node;
55 | - (id) visitSimpleTag:(HBAstSimpleTag*)node;
56 | - (id) visitTag:(HBAstTag*)node;
57 |
58 | // Expressions
59 |
60 | - (id) visitContextualValue:(HBAstContextualValue*)node;
61 | - (id) visitExpression:(HBAstExpression*)node;
62 | - (id) visitKeyPathComponent:(HBAstKeyPathComponent*)node;
63 | - (id) visitNumber:(HBAstNumber*)node;
64 | - (id) visitString:(HBAstString*)node;
65 | - (id) visitValue:(HBAstValue*)node;
66 | - (id) visitParametersHash:(HBAstParametersHash*)node;
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/src/handlebars-objc/astVisitors/HBAstVisitor.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBAstVisitor.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBAstVisitor.h"
29 | #import "HBAst.h"
30 |
31 | @implementation HBAstVisitor
32 |
33 | - (id) initWithRootAstNode:(HBAstNode*) rootNode;
34 | {
35 | self = [super init];
36 | self.rootNode = rootNode;
37 | return self;
38 | }
39 |
40 | - (id) visitNode:(HBAstNode*)node
41 | {
42 | return [node accept:self];
43 | }
44 |
45 |
46 | #pragma mark -
47 | #pragma mark High-level nodes
48 |
49 | - (id) visitBlock:(HBAstBlock*)node
50 | {
51 | return nil;
52 | }
53 |
54 | - (id) visitComment:(HBAstComment*)node
55 | {
56 | return nil;
57 | }
58 |
59 | - (id) visitPartialTag:(HBAstPartialTag*)node
60 | {
61 | return nil;
62 | }
63 |
64 | - (id) visitProgram:(HBAstProgram*)node
65 | {
66 | return nil;
67 | }
68 |
69 | - (id) visitRawText:(HBAstRawText*)node
70 | {
71 | return nil;
72 | }
73 |
74 | - (id) visitSimpleTag:(HBAstSimpleTag*)node
75 | {
76 | return nil;
77 | }
78 |
79 | - (id) visitTag:(HBAstTag*)node
80 | {
81 | return nil;
82 | }
83 |
84 |
85 | #pragma mark -
86 | #pragma mark Expressions
87 |
88 | - (id) visitContextualValue:(HBAstContextualValue*)node
89 | {
90 | return nil;
91 | }
92 |
93 | - (id) visitExpression:(HBAstExpression*)node
94 | {
95 | return nil;
96 | }
97 |
98 | - (id) visitKeyPathComponent:(HBAstKeyPathComponent*)node
99 | {
100 | return nil;
101 | }
102 |
103 | - (id) visitNumber:(HBAstNumber*)node
104 | {
105 | return nil;
106 | }
107 |
108 | - (id) visitString:(HBAstString*)node
109 | {
110 | return nil;
111 | }
112 |
113 | - (id) visitValue:(HBAstValue*)node
114 | {
115 | return nil;
116 | }
117 |
118 | - (id) visitParametersHash:(HBAstParametersHash*)node
119 | {
120 | return nil;
121 | }
122 |
123 | #pragma mark -
124 |
125 | - (void) dealloc
126 | {
127 | self.rootNode = nil;
128 | [super dealloc];
129 | }
130 |
131 |
132 | @end
133 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBContextRendering.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBContextRendering.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/1/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | // You can add your own rendering to an ObjC class by implementing the HBContextRendering
31 | // protocol.
32 |
33 | @protocol HBContextRendering
34 | - (NSString*) renderValueForHandlebars;
35 | @end
36 |
37 | extern NSString* renderForHandlebars(id object);
38 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBContextRendering.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBContextRendering.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/1/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBContextRendering.h"
29 |
30 | // We used to use categories on NSNumber, NSString ... but on ios, we generate
31 | // a static library and using categories with categories requires adding -ObjC
32 | // to the linker, and this is not something we want.
33 | //
34 | // Instead we now use isKindOfClass (and this sucks).
35 | //
36 |
37 | NSString* renderForHandlebars(id object)
38 | {
39 | if (nil == object) return nil;
40 | NSString* renderedValue = nil;
41 | if ([object respondsToSelector:@selector(renderValueForHandlebars)]) {
42 | renderedValue = [object renderValueForHandlebars];
43 | } else {
44 | // see remark about objc categories and static libraries above
45 | if ([object isKindOfClass:[NSString class]]) {
46 | renderedValue = object;
47 | } else if ([object isKindOfClass:[NSNumber class]]) {
48 | renderedValue = [object description];
49 | } else {
50 | // last resort, return nil. If wanted, another behaviour for individual classes can be provided via the implementation of HBContextRendering Protocol
51 | renderedValue = nil;
52 | }
53 | }
54 | return renderedValue;
55 | }
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBContextStack.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBContextStack.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/30/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @class HBContextState;
31 |
32 | @interface HBContextStack : NSObject
33 |
34 | @property (readonly) HBContextState* current;
35 |
36 | - (void) push:(HBContextState*)state;
37 | - (void) pop;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBContextStack.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBContextStack.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/30/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBContextStack.h"
29 | #import "HBContextState.h"
30 |
31 | @interface HBContextStack()
32 | @property (readwrite, retain, nonatomic) HBContextState* current;
33 | @end
34 |
35 | @implementation HBContextStack
36 |
37 |
38 | - (void) push:(HBContextState*)state
39 | {
40 | state.parent = self.current;
41 | self.current = state;
42 |
43 | // Line below implements one part of the
44 | // "Private variables provided via the data option are available in all descendent scopes."
45 | // from http://handlebarsjs.com/block_helpers.html
46 | // by always copying current data context to new pushed contexts if they don't
47 | // already have one.
48 | //
49 | // The other part is up to block helpers that make sure they always copy their inherited
50 | // data context when creating a new one.
51 | //
52 | // This is a bit fragile and inelegant. We might want to replace this with a bottom-up
53 | // traveral of stacked data context at evaluation time.
54 | // This would be less fragile, more element, but probably less efficient in some cases.
55 | if ((state.dataContext == nil) && state.parent) state.dataContext = state.parent.dataContext;
56 | }
57 |
58 | - (void) pop
59 | {
60 | HBContextState* state = self.current;
61 | if (state) {
62 | self.current = state.parent;
63 | }
64 | }
65 |
66 | #pragma mark -
67 |
68 | - (void) dealloc
69 | {
70 | self.current = nil;
71 | [super dealloc];
72 | }
73 | @end
74 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBContextState.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBContextState.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/30/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @class HBAstContextualValue;
31 | @class HBDataContext;
32 |
33 | @interface HBContextState : NSObject
34 |
35 | @property (retain, nonatomic) id context;
36 | @property (retain, nonatomic) HBDataContext* dataContext;
37 | @property (retain, nonatomic) NSDictionary* mergedAttributes;
38 | @property (retain, nonatomic) HBContextState* parent;
39 |
40 | + (instancetype)stateWithContext:(id)context data:(HBDataContext*)data;
41 |
42 | - (id) evaluateContextualValue:(HBAstContextualValue*)value;
43 |
44 | - (HBDataContext*) dataContextCopyOrNew NS_RETURNS_RETAINED; // must be released by sender as per usual conventions on copy and new
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBContextState.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBContextState.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/30/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBContextState.h"
29 | #import "HBAstContextualValue.h"
30 | #import "HBDataContext.h"
31 | #import "HBObjectPropertyAccess.h"
32 |
33 | @implementation HBContextState
34 |
35 | + (instancetype)stateWithContext:(id)context data:(HBDataContext*)data
36 | {
37 | HBContextState* result = [[[[self class] alloc] init] autorelease];
38 | result.context = context;
39 | result.dataContext = data;
40 | return result;
41 | }
42 |
43 | - (id) valueForKey:(NSString*)key context:(id)context includeMergedAttributes:(BOOL)includeMergedAttributes
44 | {
45 | if (!context) return nil;
46 | id result;
47 | if (includeMergedAttributes && self.mergedAttributes && self.mergedAttributes[key]) {
48 | return self.mergedAttributes[key];
49 | }
50 |
51 | @try {
52 | result = [HBObjectPropertyAccess valueForKey:key onObject:context];
53 | }
54 | @catch (NSException* e) {
55 | result = nil;
56 | }
57 |
58 | return result;
59 | }
60 |
61 | - (id) evaluateContextualValue:(HBAstContextualValue*)value
62 | {
63 | NSUInteger index = 0;
64 | id current = nil;
65 | NSArray* pathComponents = value.keyPath;
66 |
67 | HBContextState* startState = self;
68 |
69 | // consume "." components if any
70 | if (pathComponents.count > 0 && ([[pathComponents[0] key] isEqualToString:@"this"] || [[pathComponents[0] key] isEqualToString:@"."])) index++;
71 |
72 | // consume ".." components if any
73 | while (index < pathComponents.count && [[pathComponents[index] key] isEqualToString:@".."] && startState) {
74 | index++;
75 | startState = startState.parent;
76 | }
77 | if (!startState) return nil;
78 | current = startState.context;
79 |
80 | // if node is a value, first component (after "." and ".." components) is a data value
81 | if (value.isDataValue) {
82 | NSAssert(pathComponents && pathComponents.count > index, @"no keypath in data value");
83 | NSString* key = [value.keyPath[index] key];
84 | current = startState.dataContext ? startState.dataContext[key] : nil;
85 | index++;
86 | }
87 |
88 | // consume remaining "normal" keypath
89 | BOOL atRootLevel = true;
90 | while (index < pathComponents.count && current) {
91 | NSString* key = [pathComponents[index] key];
92 | current = [self valueForKey:key context:current includeMergedAttributes:atRootLevel];
93 | atRootLevel = false;
94 | index++;
95 | }
96 |
97 | return current;
98 | }
99 |
100 | - (HBDataContext*) dataContextCopyOrNew
101 | {
102 | if (self.dataContext) return [self.dataContext copy];
103 | return [HBDataContext new];
104 | }
105 |
106 | #pragma mark -
107 |
108 | - (void) dealloc
109 | {
110 | self.context = nil;
111 | self.dataContext = nil;
112 | self.mergedAttributes = nil;
113 | self.parent = nil;
114 | [super dealloc];
115 | }
116 |
117 | @end
118 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBDataContext.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBDataContext.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/2/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | /**
31 | Handlebars.js supports private variables set by block helpers and available to
32 | descendant scopes (See [block helpers](http://handlebarsjs.com/block_helpers.html)
33 | on Handlebars.js).
34 |
35 | Support for private data is provided by data context. In addition to context,
36 | helpers receive an HBDataContext in their calling info (see <[HBHelperCallingInfo data]>)
37 | holding all currently set private variables.
38 |
39 | Variables can be accessed using the dataForKey/setData:forKey accessors or directly
40 | using objective-C keyed subscripting operators.
41 |
42 | ## Setting variables in helpers ##
43 |
44 | When setting variables in a helper, you *MUST NEVER* modify passed context directly.
45 | You *MUST* copy the data context your received, copy it (using ), modify it
46 | and then pass it to children statements (See <-[HBHelperCallingInfo statements]> for more
47 | information about statements)
48 |
49 | */
50 | @interface HBDataContext : NSObject
51 |
52 | /** @name accessing variables */
53 |
54 | /**
55 | get the value of a private variable
56 |
57 | @param key name of the private variable to retrieve
58 | @return the value of private variable. Can be any objective-C value.
59 | */
60 | - (id) dataForKey:(NSString*)key;
61 |
62 | /**
63 | set the value of a private variable
64 |
65 | @param data value of private variable
66 | @param key the name of the private variable
67 | */
68 | - (void) setData:(id)data forKey:(NSString*)key;
69 |
70 | /** @name Copying data contexts */
71 |
72 | /**
73 | copy receiver
74 |
75 | Using this method is the roper way to copy data context in helpers implementation.
76 | This is generally done only when setting a new private variable passed to
77 | children scopes.
78 |
79 | @return a copy of the receiver
80 | */
81 | - (id) copy;
82 |
83 | /** @name objc litteral compatibility */
84 |
85 | /**
86 | keyed subscripting read accessor
87 |
88 | You generally do not call this method directly. Instead, use objective-C subscripting operators.
89 | This method calls .
90 |
91 | @param key name of the private variable to retrieve
92 | @return the value of private variable. Can be any objective-C value.
93 | */
94 | - (id)objectForKeyedSubscript:(id)key;
95 |
96 | /**
97 | keyed subscripting write accessor
98 |
99 | You generally do not call this method directly. Instead, use objective-C subscripting operators.
100 | This method calls .
101 |
102 | @param object value of private variable
103 | @param aKey name of the private variable to retrieve
104 | */
105 | - (void)setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey;
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBDataContext.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBDataContext.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/2/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBDataContext.h"
29 |
30 | @interface HBDataContext()
31 | @property (retain, nonatomic) NSMutableDictionary* data;
32 | @end
33 |
34 |
35 | @implementation HBDataContext
36 |
37 | - (id)copy
38 | {
39 | HBDataContext* other = [[[self class] alloc] init];
40 | other.data = [[self.data mutableCopy] autorelease];
41 | return other;
42 | }
43 |
44 | - (id) dataForKey:(NSString*)key
45 | {
46 | if (nil == self.data) return nil;
47 | return self.data[key];
48 | }
49 |
50 | - (void) setData:(id)data forKey:(NSString*)key
51 | {
52 | if (nil == self.data) {
53 | self.data = [[NSMutableDictionary new] autorelease];
54 | }
55 |
56 | self.data[key] = data;
57 | }
58 |
59 | // objc litteral compatibility
60 |
61 | - (id)objectForKeyedSubscript:(id)key
62 | {
63 | return [self dataForKey:key];
64 | }
65 |
66 | - (void)setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey
67 | {
68 | NSAssert([(NSObject*)aKey isKindOfClass:[NSString class]], @"data keys must be strings");
69 | [self setData:object forKey:(NSString*)aKey];
70 | }
71 |
72 | #pragma mark -
73 |
74 | - (void) dealloc
75 | {
76 | self.data = nil;
77 | [super dealloc];
78 | }
79 | @end
80 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBHandlebarsKVCValidation.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBHandlebarsKVCValidation.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/17/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | /**
31 | Protocol your data classes should implement to filter what keys can be accessed by Handlebars templates.
32 | If you don't implement this protocol, only objective-C properties will be accessible.
33 |
34 | */
35 | @protocol HBHandlebarsKVCValidation
36 |
37 | /**
38 | List the name of the property Handlebars can access on this class via KVC
39 |
40 | Your object should implement this method to fine-tune the values handlebars can access using Key-Value Coding.
41 | By default, only declared properties can be accessed by Handlebars (except for CoreData NSManagedObjects where all CoreData properties are accessible).
42 |
43 | @return the list of accessible properties on the class
44 | */
45 | + (NSArray*) validKeysForHandlebars;
46 | @end
47 |
--------------------------------------------------------------------------------
/src/handlebars-objc/context/HBObjectPropertyAccess.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBObjectPropertyAccessor.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/15/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 |
29 | #import
30 |
31 | // Utility that checks access to values on contexts.
32 | @interface HBObjectPropertyAccess : NSObject
33 |
34 | + (id) valueForKey:(NSString *)key onObject:(id)object;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/src/handlebars-objc/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/src/handlebars-objc/errorHandling/HBErrorHandling.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBErrorHandling.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 |
31 | extern NSString* HBErrorDomain;
32 |
33 |
34 | /**
35 | Error codes used in handlebars-obc
36 | */
37 | typedef NS_ENUM(NSInteger, HBErrorCode) {
38 | /** used when a parse error occurs */
39 | HBErrorCodeGenericParseError = 0,
40 | /** used when a helper referenced in a template doesn't exist */
41 | HBErrorCodeHelperMissingError = 100,
42 | /** used when a partial references in a template doesn't exist */
43 | HBErrorCodePartialMissingError = 200
44 | };
45 |
46 | /**
47 | HBParseError errors can be generated when a template file contains errors.
48 | */
49 | @interface HBParseError: NSError
50 |
51 | /**
52 | line number where error can be found
53 | */
54 | - (NSInteger) lineNumber;
55 |
56 | /**
57 | position in buffer of error
58 | */
59 | - (NSInteger) positionInBuffer;
60 |
61 | /**
62 | string containing the buffer area around error
63 | */
64 | - (NSString*) contextInBuffer;
65 |
66 | /**
67 | a detailed error string returned by low-level parser.
68 | */
69 | - (NSString*) lowLevelParserDescription;
70 |
71 | @end
72 |
73 |
74 | /**
75 | HBHelperMissingError instances can be generated when a helper was invoked in a template but could not be found at runtime.
76 | */
77 | @interface HBHelperMissingError: NSError
78 |
79 | /**
80 | name of the missing helper
81 | */
82 | - (NSString*) helperName;
83 |
84 | @end
85 |
86 | /**
87 | HBPartialMissingError instances can be generated when a partial was referenced in a template but could not be found at runtime.
88 | */
89 | @interface HBPartialMissingError: NSError
90 |
91 | /**
92 | name of the missing partial
93 | */
94 | - (NSString*) partialName;
95 |
96 | @end
--------------------------------------------------------------------------------
/src/handlebars-objc/errorHandling/HBErrorHandling_Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBErrorHandling_Private.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 |
29 | @interface HBParseError()
30 |
31 | + (instancetype) parseErrorWithLineNumber:(NSInteger)lineNumber positionInBuffer:(NSInteger)positionInBuffer contextInBuffer:(NSString*)context lowLevelParserDescription:(NSString*)parserError;
32 |
33 | @end
34 |
35 | @interface HBHelperMissingError()
36 |
37 | + (instancetype) HBHelperMissingErrorWithHelperName:(NSString*)helperName;
38 |
39 | @end
40 |
41 | @interface HBPartialMissingError()
42 |
43 | + (instancetype) HBPartialMissingErrorWithPartialName:(NSString*)partialName;
44 |
45 | @end
--------------------------------------------------------------------------------
/src/handlebars-objc/handlebars-objc-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | FMWK
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | NSHumanReadableCopyright
26 | Copyright © 2013 Fotonauts. All rights reserved.
27 | NSPrincipalClass
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/handlebars-objc/handlebars-objc-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #ifdef __OBJC__
8 | #import
9 | #endif
10 |
--------------------------------------------------------------------------------
/src/handlebars-objc/handlebars-objc-ios-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #ifdef __OBJC__
8 | #import
9 | #endif
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBBuiltinHelpersRegistry.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBBuiltinHelpersRegistry.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/5/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 | #import "HBHelperRegistry.h"
30 |
31 | @interface HBBuiltinHelpersRegistry : HBHelperRegistry
32 |
33 | + (void) initialize;
34 | + (instancetype) builtinRegistry;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBEscapedString.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBEscapedString.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 4/3/14.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @interface HBEscapedString : NSString
31 | {
32 | NSString* _actualString;
33 | }
34 | @end
35 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBEscapedString.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBEscapedString.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 4/3/14.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBEscapedString.h"
29 |
30 | @implementation HBEscapedString
31 |
32 | - (id)init
33 | {
34 | self = [super init];
35 | if (self) {
36 | self->_actualString = [[NSString alloc] init];
37 | }
38 | return self;
39 | }
40 |
41 | - (id)initWithString:(NSString*)otherString
42 | {
43 | self = [super init];
44 | if (self) {
45 | self->_actualString = [otherString retain];
46 | }
47 | return self;
48 | }
49 |
50 | - (void)dealloc
51 | {
52 | [_actualString release];
53 | _actualString = nil;
54 | [super dealloc];
55 | }
56 |
57 | - (NSString*)actualString
58 | {
59 | return _actualString;
60 | }
61 |
62 | //
63 | // Those two methods are the minimum we must implement to be a valid NSString subclass
64 | // We never really use any NSString method beyond -initWithString: however
65 | //
66 | - (NSUInteger)length
67 | {
68 | return [_actualString length];
69 | }
70 |
71 | - (unichar)characterAtIndex:(NSUInteger)index
72 | {
73 | return [_actualString characterAtIndex:index];
74 | }
75 |
76 | @end
77 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBEscapedString_Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBEscapedString_Private.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 4/3/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "HBEscapedString.h"
10 |
11 | @interface HBEscapedString ()
12 |
13 | - (NSString*)actualString;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBHelper.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBHelper.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/2/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @class HBHelperCallingInfo;
31 | typedef NSString* (^HBHelperBlock)(HBHelperCallingInfo* info);
32 |
33 | #import "HBHelperCallingInfo.h"
34 |
35 | /**
36 |
37 | HBHelper is the class representing Handlebars helpers. Currently, the only way to implement a helper in handlebars-objc is to provide a block of type HBHelperBlock:
38 |
39 | typedef NSString* (^HBHelperBlock)(HBHelperCallingInfo* callingInfo);
40 |
41 | You generally do not create HBHelper instances directly, but instead directly provide a block helper to the global execution context (see HBTemplate (See <
42 | In templates, helpers can be called with parameters (see [Handlebars.js]( http://handlebarsjs.com/expressions.html )).
43 | Those calling parameters as well as the current context are available in the callingInfo parameter.
44 |
45 | Please see for more details.
46 | */
47 | @class HBDataContext;
48 |
49 | @interface HBHelper : NSObject
50 |
51 | /**
52 | block executed by helper
53 | */
54 | @property (copy) HBHelperBlock block;
55 |
56 | @end
57 |
58 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBHelper.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBHelper.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/2/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBHelper.h"
29 |
30 |
31 | @implementation HBHelper
32 |
33 | - (void)dealloc
34 | {
35 | self.block = nil;
36 |
37 | [super dealloc];
38 | }
39 |
40 | @end
41 |
42 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBHelperCallingInfo.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBHelperCallingInfo.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBHelperCallingInfo.h"
29 | #import "HBHelperCallingInfo_Private.h"
30 | #import "HBAstEvaluationVisitor.h"
31 |
32 | @implementation HBHelperCallingInfo
33 |
34 | - (id) objectAtIndexedSubscript:(NSUInteger)index
35 | {
36 | if (!self.positionalParameters) return nil;
37 | return self.positionalParameters[index];
38 | }
39 |
40 | // Named parameters can be accessed using keyed subscript API
41 |
42 | - (id)objectForKeyedSubscript:(id)key
43 | {
44 | if (!self.namedParameters) return nil;
45 | return self.namedParameters[key];
46 | }
47 |
48 | - (NSString*) escapeString:(NSString*)rawString
49 | {
50 | return [self.evaluationVisitor escapeStringAccordingToCurrentMode:rawString];
51 | }
52 |
53 | #pragma mark -
54 |
55 | - (void) dealloc
56 | {
57 | self.context = nil;
58 | self.data = nil;
59 | self.positionalParameters = nil;
60 | self.namedParameters = nil;
61 | self.template = nil;
62 | self.statements = nil;
63 | self.inverseStatements = nil;
64 | [super dealloc];
65 | }
66 | @end
67 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBHelperCallingInfo_Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBHelperCallingInfo_Private.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBHelperCallingInfo.h"
29 | #import "HBAstEvaluationVisitor.h"
30 |
31 | @interface HBHelperCallingInfo ()
32 |
33 | @property (readwrite, retain, nonatomic) id context;
34 | @property (readwrite, retain, nonatomic) HBDataContext* data;
35 |
36 | @property (readwrite, retain, nonatomic) NSArray* positionalParameters;
37 | @property (readwrite, retain, nonatomic) NSDictionary* namedParameters;
38 |
39 | @property (readwrite, assign, nonatomic) HBHelperInvocationKind invocationKind;
40 |
41 | @property (readwrite, copy, nonatomic) HBStatementsEvaluator statements;
42 | @property (readwrite, copy, nonatomic) HBStatementsEvaluator inverseStatements;
43 |
44 | @property (readwrite, retain, nonatomic) HBTemplate* template;
45 |
46 | @property (readwrite, assign, nonatomic) HBAstEvaluationVisitor* evaluationVisitor;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/src/handlebars-objc/helpers/HBHelperRegistry.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBHelperRegistry.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/2/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBHelperRegistry.h"
29 |
30 | @interface HBHelperRegistry()
31 | @property (retain, nonatomic) NSMutableDictionary* helpers;
32 | @end
33 |
34 | @implementation HBHelperRegistry
35 |
36 | + (instancetype) registry
37 | {
38 | return [[[self alloc] init] autorelease];
39 | }
40 |
41 | - (NSMutableDictionary*) helpers
42 | {
43 | @synchronized(self) {
44 | if (!_helpers) {
45 | _helpers = [NSMutableDictionary new];
46 | }
47 | }
48 | return _helpers;
49 | }
50 |
51 | - (HBHelper*) helperForName:(NSString*)name;
52 | {
53 | if (nil == self.helpers) return nil;
54 | HBHelper* result;
55 | @synchronized(self.helpers) {
56 | result = self.helpers[name];
57 | }
58 | return result;
59 | }
60 |
61 | - (void) setHelper:(HBHelper*)helper forName:(NSString*)name;
62 | {
63 | @synchronized(self.helpers) {
64 | self.helpers[name] = helper;
65 | }
66 | }
67 |
68 | - (void) addHelpers:(NSDictionary*)helpers
69 | {
70 | for (NSString* name in helpers) {
71 | [self setHelper:helpers[name] forName:name];
72 | }
73 | }
74 |
75 | - (void) removeHelperForName:(NSString*)name
76 | {
77 | @synchronized(self.helpers) {
78 | [self.helpers removeObjectForKey:name];
79 | }
80 | }
81 |
82 | - (void) removeAllHelpers
83 | {
84 | @synchronized(self.helpers) {
85 | [self.helpers removeAllObjects];
86 | }
87 | }
88 |
89 | // objc litteral compatibility
90 |
91 | - (id) objectForKeyedSubscript:(id)key
92 | {
93 | return [self helperForName:key];
94 | }
95 |
96 | - (void) setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey
97 | {
98 | NSAssert([(NSObject*)aKey isKindOfClass:[NSString class]], @"helper names must be strings");
99 | NSAssert([(NSObject*)object isKindOfClass:[HBHelper class]], @"helper objects must be substrings of HBHelper class");
100 |
101 | [self setHelper:object forName:(NSString*)aKey];
102 | }
103 |
104 | #pragma mark -
105 | #pragma mark ObjC block API
106 |
107 | - (void) registerHelperBlock:(HBHelperBlock)block forName:(NSString*)name
108 | {
109 | HBHelper* helper = [HBHelper new];
110 | helper.block = block;
111 | self[name] = helper;
112 | [helper release];
113 | }
114 |
115 | - (void) registerHelperBlocks:(NSDictionary *)helperBlocks
116 | {
117 | for (NSString* name in helperBlocks) {
118 | [self registerHelperBlock:helperBlocks[name] forName:name];
119 | }
120 | }
121 |
122 | #pragma mark -
123 |
124 | - (void) dealloc
125 | {
126 | self.helpers = nil;
127 | [super dealloc];
128 | }
129 |
130 | @end
131 |
--------------------------------------------------------------------------------
/src/handlebars-objc/parser/HBParser.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBParser.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/26/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | @class HBAstProgram;
31 |
32 | @interface HBParser : NSObject
33 |
34 | + (HBAstProgram*)astFromString:(NSString*)text error:(NSError**)error;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/src/handlebars-objc/parser/HBParser.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBParser.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 9/26/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBParser.h"
29 | #import "HBAst.h"
30 | #import "HBHandlebars.h"
31 | #import "HBErrorHandling_Private.h"
32 |
33 |
34 | extern id astFromString(NSString* text, NSError** error);
35 |
36 | extern int hb_column;
37 |
38 | @implementation HBParser
39 |
40 | + (HBAstProgram*)astFromString:(NSString*)text error:(NSError **)error
41 | {
42 | HBAstProgram* program = nil;
43 |
44 | hb_column = 1;
45 |
46 | NSError* lowerLevelError = nil;
47 | program = astFromString(text, &lowerLevelError);
48 |
49 | if (lowerLevelError == nil) return program;
50 |
51 | // everything from now on is error handling
52 | if ([lowerLevelError isKindOfClass:[HBParseError class]]) {
53 | HBParseError* parseError = (HBParseError*)lowerLevelError;
54 |
55 | NSInteger pos = parseError.positionInBuffer;
56 | NSInteger posMin = MAX(0, pos - 30);
57 | NSInteger posMax = MIN(pos + 30, [text length] - 1);
58 |
59 | NSString* extractedText = [text substringWithRange:NSMakeRange(posMin, posMax - posMin)];
60 |
61 |
62 | NSString* error = [NSString stringWithFormat:@"%@\nline %ld\n'%@'", parseError.lowLevelParserDescription, (long int)parseError.lineNumber, extractedText];
63 | [HBHandlebars log:1 object:error];
64 |
65 | if (error) lowerLevelError = [HBParseError parseErrorWithLineNumber:parseError.lineNumber positionInBuffer:parseError.positionInBuffer contextInBuffer:extractedText lowLevelParserDescription:parseError.lowLevelParserDescription];
66 | }
67 |
68 | if (error) *error = lowerLevelError;
69 |
70 | return nil;
71 | }
72 |
73 | @end
74 |
--------------------------------------------------------------------------------
/src/handlebars-objc/partials/HBPartial.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBPartial.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | /**
31 | HBPartial is the class representing partials in HBHandlebars
32 | */
33 | @interface HBPartial : NSObject
34 |
35 | /**
36 | partial string
37 | */
38 | @property (retain, nonatomic) NSString* string;
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/src/handlebars-objc/partials/HBPartial.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBPartial.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBPartial.h"
29 | #import "HBPartial_Private.h"
30 | #import "HBParser.h"
31 |
32 | @implementation HBPartial
33 |
34 | - (BOOL) compile:(NSError**)error
35 | {
36 | @synchronized(self) {
37 | if (!self._program) {
38 | self._program = [HBParser astFromString:self.string error:error];
39 | }
40 | }
41 | return (nil != self._program);
42 | }
43 |
44 | - (NSArray*) astStatements
45 | {
46 | return self._program.statements;
47 | }
48 |
49 | #pragma mark -
50 |
51 | - (void) dealloc
52 | {
53 | self.string = nil;
54 | self._program = nil;
55 | [super dealloc];
56 | }
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/src/handlebars-objc/partials/HBPartialRegistry.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBPartialRegistry.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBPartialRegistry.h"
29 | #import "HBPartial.h"
30 |
31 | @interface HBPartialRegistry()
32 | @property (retain, nonatomic) NSMutableDictionary* partials;
33 | @end
34 |
35 | @implementation HBPartialRegistry
36 |
37 | - (NSMutableDictionary*) partials
38 | {
39 | @synchronized(self) {
40 | if (!_partials) {
41 | _partials = [NSMutableDictionary new];
42 | }
43 | }
44 | return _partials;
45 | }
46 |
47 | - (HBPartial*) partialForName:(NSString*)key;
48 | {
49 | if (nil == self.partials) return nil;
50 | HBPartial* result;
51 | @synchronized(self.partials) {
52 | result = self.partials[key];
53 | }
54 | return result;
55 | }
56 |
57 | - (void) registerPartial:(HBPartial*)partial forName:(NSString*)key;
58 | {
59 | @synchronized(self.partials) {
60 | self.partials[key] = partial;
61 | }
62 | }
63 |
64 | - (void) registerPartialString:(NSString*)partialString forName:(NSString*)partialName
65 | {
66 | HBPartial* partial = [[HBPartial alloc] init];
67 | partial.string = partialString;
68 | [self registerPartial:partial forName:partialName];
69 | [partial release];
70 | }
71 |
72 | - (void) registerPartials:(NSDictionary*)partials
73 | {
74 | for (NSString* name in partials) {
75 | [self registerPartial:partials[name] forName:name];
76 | }
77 | }
78 |
79 | - (void) registerPartialStrings:(NSDictionary* /* NSString -> NSString */)partials
80 | {
81 | for (NSString* partialName in partials) {
82 | NSString* partialString = partials[partialName];
83 | NSAssert([partialString isKindOfClass:[NSString class]], @"partial strings must be of class NSString");
84 | HBPartial* partial = [[HBPartial alloc] init];
85 | partial.string = partialString;
86 | [self registerPartial:partial forName:partialName];
87 | [partial release];
88 | }
89 | }
90 |
91 | - (void) unregisterPartialForName:(NSString*)name
92 | {
93 | @synchronized(self.partials) {
94 | [self.partials removeObjectForKey:name];
95 | }
96 | }
97 |
98 | - (void) unregisterAllPartials;
99 | {
100 | @synchronized(self.partials) {
101 | [self.partials removeAllObjects];
102 | }
103 | }
104 |
105 | // objc litteral compatibility
106 |
107 | - (id) objectForKeyedSubscript:(id)key
108 | {
109 | return [self partialForName:key];
110 | }
111 |
112 | - (void) setObject:(id)object forKeyedSubscript:(id < NSCopying >)aKey
113 | {
114 | NSAssert([(NSObject*)aKey isKindOfClass:[NSString class]], @"partial names must be strings");
115 | NSAssert([(NSObject*)object isKindOfClass:[HBPartial class]], @"partial objects must be substrings of HBPartial class");
116 |
117 | [self registerPartial:object forName:(NSString*)aKey];
118 | }
119 |
120 |
121 | #pragma mark -
122 |
123 | - (void) dealloc
124 | {
125 | self.partials = nil;
126 | [super dealloc];
127 | }
128 |
129 | @end
130 |
--------------------------------------------------------------------------------
/src/handlebars-objc/partials/HBPartial_Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBPartial_Private.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBPartial.h"
29 | #import "HBAstProgram.h"
30 |
31 | @interface HBPartial ()
32 |
33 | @property (retain, nonatomic) HBAstProgram* _program;
34 |
35 | - (BOOL) compile:(NSError**)error;
36 | - (NSArray*) astStatements;
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/src/handlebars-objc/runtime/HBEscapingFunctions.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBEscapingFunctions.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import
29 |
30 | typedef NSString* (^HBEscapingFunction)(NSString* string);
31 |
32 | @interface HBEscapingFunctions : NSObject
33 |
34 | + (HBEscapingFunction) htmlEscapingFunction;
35 | + (HBEscapingFunction) urlParameterEscapingFunction;
36 |
37 | @end
38 |
39 |
--------------------------------------------------------------------------------
/src/handlebars-objc/runtime/HBEscapingFunctions.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBEscapingFunctions.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/29/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBEscapingFunctions.h"
29 | #import "HBHelperUtils.h"
30 |
31 | @implementation HBEscapingFunctions
32 |
33 | + (HBEscapingFunction) htmlEscapingFunction
34 | {
35 | static dispatch_once_t pred;
36 | static HBEscapingFunction _htmlEscapingFunction = nil;
37 |
38 | dispatch_once(&pred, ^{
39 | _htmlEscapingFunction = ^(NSString* string) {
40 | return [HBHelperUtils escapeHTML:string];
41 | };
42 | });
43 |
44 | return _htmlEscapingFunction;
45 | }
46 |
47 | + (HBEscapingFunction) urlParameterEscapingFunction
48 | {
49 |
50 | static dispatch_once_t pred;
51 | static HBEscapingFunction _urlParameterEscapingFunction = nil;
52 |
53 | dispatch_once(&pred, ^{
54 | _urlParameterEscapingFunction = ^(NSString* string) {
55 | return [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]];
56 | };
57 | });
58 |
59 | return _urlParameterEscapingFunction;
60 | }
61 |
62 | @end
63 |
--------------------------------------------------------------------------------
/src/handlebars-objc/runtime/HBExecutionContextDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBExecutionContextDelegate.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/19/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "HBHelper.h"
11 | #import "HBEscapingFunctions.h"
12 |
13 | @class HBExecutionContext;
14 | @class HBPartial;
15 |
16 | /**
17 | HBExecutionContext delegate protocol
18 |
19 | By implementing an execution context delegate you can control certain of its behaviours.
20 | All the methods from this protocol are optional.
21 |
22 | # Tasks #
23 |
24 | Provide your own helper provisioning mechanism using
25 |
26 | Provide your own partial provisioning mechanism by implementing
27 |
28 | */
29 |
30 | @protocol HBExecutionContextDelegate
31 |
32 | @optional
33 |
34 | /**
35 | return a helper block with a given name
36 |
37 | Implement this method if you want to implement your own helper organization mechanism.
38 |
39 | @param name name of the helper
40 | @param executionContext the execution context requesting the helper. Useful if your delegate is the delegate of serveral execution contexts.
41 | @return a helper block
42 | @since v1.1.0
43 | */
44 | - (HBHelperBlock) helperBlockWithName:(NSString*)name forExecutionContext:(HBExecutionContext*)executionContext;
45 |
46 | /**
47 | return a partial string with a given name
48 |
49 | Implement this method if you want to implement your own partial organization mechanism.
50 |
51 | @param name name of the partial
52 | @param executionContext the execution context requesting the partial string. Useful if your delegate is the delegate of serveral execution contexts.
53 | @return a partial string
54 | @since v1.1.0
55 | */
56 | - (NSString*) partialStringWithName:(NSString*)name forExecutionContext:(HBExecutionContext*)executionContext;
57 |
58 |
59 | /**
60 | return a partial with a given name
61 |
62 | Implement this method if you want to implement your own partial organization mechanism.
63 |
64 | @param name name of the partial
65 | @param executionContext the execution context requesting the partial. Useful if your delegate is the delegate of serveral execution contexts.
66 | @return the partial (can be nil)
67 | @since v1.1.0
68 | */
69 | - (HBPartial*) partialWithName:(NSString*)name forExecutionContext:(HBExecutionContext*)executionContext;
70 |
71 |
72 | /**
73 | Return the localized version of a string.
74 |
75 | Implement this method if you want to provide you own localization mechanism.
76 | This method is called by helpers using the built-in localization mechanism in handlebars-objc. One such helper is the "localize" built-in helper.
77 |
78 | @param string the string to localize
79 | @param executionContext the execution context requesting the localized string.
80 | @return the localized version of the string
81 | @since v1.1.0
82 | */
83 | - (NSString*) localizedString:(NSString*)string forExecutionContext:(HBExecutionContext*)executionContext;
84 |
85 | /**
86 | Return the escaped version of a string for a target text mode
87 |
88 | Implement this method if you want to provide a specific escaping mechanism for a target format. If your delegate does not support the escaping of a format, this function should return nil.
89 |
90 | @param rawString string to escape
91 | @param formatName the name of current mode. When mode is a well-known text format, it is generally a mime-type ("text/html" for html, "application/javascript" for javascript, ...).
92 | @param executionContext the execution context requesting the escaped string
93 | @return the escaped string or nil if this format is not supported by the delegate
94 | @since v1.1.0
95 | */
96 | - (NSString*) escapeString:(NSString*)rawString forTargetFormat:(NSString*)formatName forExecutionContext:(HBExecutionContext*)executionContext;
97 |
98 |
99 | @end
100 |
--------------------------------------------------------------------------------
/src/handlebars-objc/runtime/HBExecutionContext_Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBExecutionContext_Private.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 11/2/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface HBExecutionContext ()
12 |
13 | - (NSString*) localizedString:(NSString*)string;
14 | - (NSString*) escapeString:(NSString*)rawString forTargetFormat:(NSString*)formatName;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/src/handlebars-objc/runtime/HBTemplate_Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBTemplate_Private.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 10/4/13.
6 | //
7 | // The MIT License
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | //
27 |
28 | #import "HBTemplate.h"
29 | #import "HBEscapingFunctions.h"
30 |
31 | @class HBAstProgram;
32 | @class HBExecutionContext;
33 | @class HBPartial;
34 |
35 | @interface HBTemplate()
36 |
37 | @property (readwrite) BOOL compiled;
38 | @property (retain, nonatomic) HBAstProgram* program;
39 | @property (retain, nonatomic) HBExecutionContext* templateLocalExecutionContext;
40 | @property (retain, nonatomic) HBExecutionContext* sharedExecutionContext;
41 |
42 | - (HBHelper*) helperForName:(NSString*)name;
43 | - (HBPartial*) partialForName:(NSString*)name;
44 |
45 | - (NSString*) escapeString:(NSString*)rawString forTargetFormat:(NSString*)formatName;
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/src/handlebars-objcTests/HBTestCase.h:
--------------------------------------------------------------------------------
1 | //
2 | // HBTestCase.h
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 3/18/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface HBTestCase : XCTestCase
12 |
13 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)blocks withPartials:(NSDictionary*)partials error:(NSError**)error;
14 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)blocks withPartials:(NSDictionary*)partials;
15 |
16 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withPartials:(NSDictionary*)partials error:(NSError**)error;
17 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withPartials:(NSDictionary*)partials;
18 |
19 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)blocks error:(NSError**)error;
20 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)blocks;
21 |
22 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context error:(NSError**)error;
23 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/src/handlebars-objcTests/HBTestCase.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBTestCase.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 3/18/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "HBTestCase.h"
10 | #import "HBHandlebars.h"
11 |
12 | @implementation HBTestCase
13 |
14 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)helpers withPartials:(NSDictionary*)partials error:(NSError**)error
15 | {
16 | return [HBHandlebars renderTemplateString:template withContext:context withHelperBlocks:helpers withPartialStrings:partials error:error];
17 | }
18 |
19 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)helpers withPartials:(NSDictionary*)partials
20 | {
21 | return [self renderTemplate:template withContext:context withHelpers:helpers withPartials:partials error:nil];
22 | }
23 |
24 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withPartials:(NSDictionary*)partials error:(NSError**)error
25 | {
26 | return [self renderTemplate:template withContext:context withHelpers:nil withPartials:partials error:error];
27 | }
28 |
29 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withPartials:(NSDictionary*)partials
30 | {
31 | return [self renderTemplate:template withContext:context withHelpers:nil withPartials:partials error:nil];
32 | }
33 |
34 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)helpers error:(NSError**)error
35 | {
36 | return [self renderTemplate:template withContext:context withHelpers:helpers withPartials:nil error:error];
37 | }
38 |
39 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context withHelpers:(NSDictionary*)helpers
40 | {
41 | return [self renderTemplate:template withContext:context withHelpers:helpers withPartials:nil error:nil];
42 | }
43 |
44 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context error:(NSError**)error
45 | {
46 | return [self renderTemplate:template withContext:context withHelpers:nil withPartials:nil error:error];
47 | }
48 |
49 | - (NSString*) renderTemplate:(NSString*)template withContext:(id)context
50 | {
51 | return [self renderTemplate:template withContext:context withHelpers:nil withPartials:nil error:nil];
52 | }
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/src/handlebars-objcTests/HBTestData.m:
--------------------------------------------------------------------------------
1 | //
2 | // HBTestData.m
3 | // handlebars-objc
4 | //
5 | // Created by Bertrand Guiheneuf on 3/25/14.
6 | // Copyright (c) 2014 Fotonauts. All rights reserved.
7 | //
8 |
9 |
10 | #import "HBTestCase.h"
11 | #import "HBHandlebars.h"
12 |
13 |
14 | @interface HBTestData : HBTestCase
15 |
16 | @end
17 |
18 | @implementation HBTestData
19 |
20 | - (HBHelperBlock) letHelper
21 | {
22 | return ^(HBHelperCallingInfo* callingInfo) {
23 |
24 | HBDataContext* currentDataContext = callingInfo.data;
25 | HBDataContext* descendantDataContext = currentDataContext ? [currentDataContext copy] : [HBDataContext new];
26 |
27 | for (NSString* paramName in callingInfo.namedParameters) {
28 | descendantDataContext[paramName] = callingInfo.namedParameters[paramName];
29 | }
30 |
31 | return callingInfo.statements(callingInfo.context, descendantDataContext);
32 | };
33 | }
34 |
35 | - (HBHelperBlock) helloHelper
36 | {
37 | return ^(HBHelperCallingInfo* callingInfo) {
38 | return [NSString stringWithFormat:@"Hello %@", callingInfo[@"noun"]];
39 | };
40 | }
41 |
42 | - (void) testDeepAtFooTriggersAutomaticTopLevelData
43 | {
44 | NSError* error = nil;
45 | id string = @"{{#let world='world'}}{{#if foo}}{{#if foo}}Hello {{@world}}{{/if}}{{/if}}{{/let}}";
46 | id hash = @{ @"foo" : @true };
47 | NSDictionary* helpers = @{ @"let" : [self letHelper]};
48 |
49 | NSString* result = [self renderTemplate:string withContext:hash withHelpers:helpers error:&error];
50 | XCTAssert(!error, @"evaluation should not generate an error");
51 | XCTAssertEqualObjects(result, @"Hello world");
52 | }
53 |
54 | - (void) testDataIsInheritedDownstream
55 | {
56 | NSError* error = nil;
57 | id string = @"{{#let foo=1 bar=2}}{{#let foo=bar.baz}}{{@bar}}{{@foo}}{{/let}}{{@foo}}{{/let}}";
58 | id hash = @{ @"bar": @{ @"baz": @"hello world" } };
59 | NSDictionary* helpers = @{ @"let" : [self letHelper]};
60 |
61 | NSString* result = [self renderTemplate:string withContext:hash withHelpers:helpers error:&error];
62 | XCTAssert(!error, @"evaluation should not generate an error");
63 | XCTAssertEqualObjects(result, @"2hello world1");
64 | }
65 |
66 | - (void) testTheRootContextCanBeLookedUpViaAtRoot
67 | {
68 | NSError* error = nil;
69 | id string = @"{{@root.foo}}";
70 | id hash = @{ @"foo" : @"hello" };
71 | NSDictionary* helpers = @{ @"let" : [self letHelper]};
72 |
73 | NSString* result = [self renderTemplate:string withContext:hash withHelpers:helpers error:&error];
74 | XCTAssert(!error, @"evaluation should not generate an error");
75 | XCTAssertEqualObjects(result, @"hello");
76 | }
77 |
78 | - (void) testDataContextCanBeClimbedUp
79 | {
80 | NSError* error = nil;
81 | id string = @"{{#let foo=1}}{{#let foo=2}}{{#let foo=3}} {{ @foo }} {{ @./foo }} {{ @../foo }} {{ @../../foo }} {{/let}}{{/let}}{{/let}}";
82 | id hash = @{};
83 | NSDictionary* helpers = @{ @"let" : [self letHelper]};
84 |
85 | NSString* result = [self renderTemplate:string withContext:hash withHelpers:helpers error:&error];
86 | XCTAssert(!error, @"evaluation should not generate an error");
87 | XCTAssertEqualObjects(result, @" 3 3 2 1 ");
88 | }
89 |
90 |
91 | @end
92 |
--------------------------------------------------------------------------------
/src/handlebars-objcTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/src/handlebars-objcTests/handlebars-objc-iosTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/handlebars-objcTests/handlebars-objcTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Podfile:
--------------------------------------------------------------------------------
1 |
2 | target 'osx-app', :exclusive => true do
3 | platform :osx, '10.11'
4 | pod 'handlebars-objc', :path => "../../../../"
5 | end
6 |
7 | target 'ios-app', :exclusive => true do
8 | platform :ios, '9.0'
9 | pod 'handlebars-objc', :path => "../../../../"
10 | end
11 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - handlebars-objc (1.3.0)
3 |
4 | DEPENDENCIES:
5 | - handlebars-objc (from `../../../../`)
6 |
7 | EXTERNAL SOURCES:
8 | handlebars-objc:
9 | :path: "../../../../"
10 |
11 | SPEC CHECKSUMS:
12 | handlebars-objc: 2a89c9d2a7d5711f74daa06c90613840464d0072
13 |
14 | COCOAPODS: 0.39.0
15 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Pods/Pods-ios-app-handlebars-objc.xcconfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Bertrand/handlebars-objc/e98bb1234c95ff7a88e6fac1c3d1df7f310ce262/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Pods/Pods-ios-app-handlebars-objc.xcconfig
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Pods/Pods-osx-app.xcconfig:
--------------------------------------------------------------------------------
1 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
2 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/handlebars-objc" "${PODS_ROOT}/Headers/handlebars-objc/HBHandlebars"
3 | OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers" -isystem "${PODS_ROOT}/Headers/handlebars-objc" -isystem "${PODS_ROOT}/Headers/handlebars-objc/HBHandlebars"
4 | OTHER_LDFLAGS = -ObjC
5 | PODS_ROOT = ${SRCROOT}/Pods
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods.xcodeproj/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods.xcodeproj/project.xcworkspace/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods.xcworkspace/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Test OSX CocoaPods
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : NSObject
12 |
13 | @property (assign) IBOutlet NSWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Test OSX CocoaPods
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import
11 |
12 | @implementation AppDelegate
13 |
14 | - (void) testIssue9
15 | {
16 | HBHelperBlock sentenceCaseBlock = ^(HBHelperCallingInfo * callingInfo) {
17 | NSString * locale = callingInfo[@"locale"];
18 | NSString * src = callingInfo[0];
19 | return [src capitalizedStringWithLocale:[[NSLocale alloc] initWithLocaleIdentifier:locale]];
20 | };
21 | [HBHandlebars registerHelperBlock:sentenceCaseBlock forName:@"sentenceCase"];
22 |
23 | NSError * error;
24 | NSString * result = [HBHandlebars renderTemplateString:@"hello {{sentenceCase value locale='en_US'}}!"
25 | withContext:@{@"value" : @"mike this is your friend george"}
26 | error:&error];
27 | NSLog(@"result : %@", result);
28 | }
29 |
30 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
31 | {
32 | [self testIssue9];
33 |
34 | NSString* evaluatedTemplate = [HBHandlebars renderTemplateString:@"Hello from {{value}}" withContext:@{ @"value" : @"Handlebars" } error:nil];
35 | NSLog(@"%@", evaluatedTemplate);
36 | }
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/Test OSX CocoaPods-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSMinimumSystemVersion
26 | ${MACOSX_DEPLOYMENT_TARGET}
27 | NSHumanReadableCopyright
28 | Copyright © 2013 Fotonauts. All rights reserved.
29 | NSMainNibFile
30 | MainMenu
31 | NSPrincipalClass
32 | NSApplication
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/Test OSX CocoaPods-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #ifdef __OBJC__
8 | #import
9 | #endif
10 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/en.lproj/Credits.rtf:
--------------------------------------------------------------------------------
1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
2 | {\colortbl;\red255\green255\blue255;}
3 | \paperw9840\paperh8400
4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
5 |
6 | \f0\b\fs24 \cf0 Engineering:
7 | \b0 \
8 | Some people\
9 | \
10 |
11 | \b Human Interface Design:
12 | \b0 \
13 | Some other people\
14 | \
15 |
16 | \b Testing:
17 | \b0 \
18 | Hopefully not nobody\
19 | \
20 |
21 | \b Documentation:
22 | \b0 \
23 | Whoever\
24 | \
25 |
26 | \b With special thanks to:
27 | \b0 \
28 | Mom\
29 | }
30 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test OSX CocoaPods/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Test OSX CocoaPods
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main(int argc, const char * argv[])
12 | {
13 | return NSApplicationMain(argc, argv);
14 | }
15 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Test iOS Application With CocoaPods
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Test iOS Application With CocoaPods
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import
11 |
12 | @implementation AppDelegate
13 |
14 |
15 | - (void) testIssue9
16 | {
17 | HBHelperBlock sentenceCaseBlock = ^(HBHelperCallingInfo * callingInfo) {
18 | NSString * locale = callingInfo[@"locale"];
19 | NSString * src = callingInfo[0];
20 | return [src capitalizedStringWithLocale:[[NSLocale alloc] initWithLocaleIdentifier:locale]];
21 | };
22 | [HBHandlebars registerHelperBlock:sentenceCaseBlock forName:@"sentenceCase"];
23 |
24 | NSError * error;
25 | NSString * result = [HBHandlebars renderTemplateString:@"hello {{sentenceCase value locale='en_US'}}!"
26 | withContext:@{@"value" : @"mike this is your friend george"}
27 | error:&error];
28 | NSLog(@"result : %@", result);
29 | }
30 |
31 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
32 | {
33 | [self testIssue9];
34 |
35 | NSString* evaluatedTemplate = [HBHandlebars renderTemplateString:@"Hello from {{value}}" withContext:@{ @"value" : @"Handlebars" } error:nil];
36 | NSLog(@"%@", evaluatedTemplate);
37 |
38 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
39 | // Override point for customization after application launch.
40 | self.window.backgroundColor = [UIColor whiteColor];
41 | [self.window makeKeyAndVisible];
42 | return YES;
43 | }
44 |
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "40x40",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "60x60",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "ipad",
20 | "size" : "29x29",
21 | "scale" : "1x"
22 | },
23 | {
24 | "idiom" : "ipad",
25 | "size" : "29x29",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "ipad",
30 | "size" : "40x40",
31 | "scale" : "1x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "40x40",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "76x76",
41 | "scale" : "1x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "76x76",
46 | "scale" : "2x"
47 | }
48 | ],
49 | "info" : {
50 | "version" : 1,
51 | "author" : "xcode"
52 | }
53 | }
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "iphone",
6 | "extent" : "full-screen",
7 | "minimum-system-version" : "7.0",
8 | "scale" : "2x"
9 | },
10 | {
11 | "orientation" : "portrait",
12 | "idiom" : "iphone",
13 | "subtype" : "retina4",
14 | "extent" : "full-screen",
15 | "minimum-system-version" : "7.0",
16 | "scale" : "2x"
17 | },
18 | {
19 | "orientation" : "portrait",
20 | "idiom" : "ipad",
21 | "extent" : "full-screen",
22 | "minimum-system-version" : "7.0",
23 | "scale" : "1x"
24 | },
25 | {
26 | "orientation" : "landscape",
27 | "idiom" : "ipad",
28 | "extent" : "full-screen",
29 | "minimum-system-version" : "7.0",
30 | "scale" : "1x"
31 | },
32 | {
33 | "orientation" : "portrait",
34 | "idiom" : "ipad",
35 | "extent" : "full-screen",
36 | "minimum-system-version" : "7.0",
37 | "scale" : "2x"
38 | },
39 | {
40 | "orientation" : "landscape",
41 | "idiom" : "ipad",
42 | "extent" : "full-screen",
43 | "minimum-system-version" : "7.0",
44 | "scale" : "2x"
45 | }
46 | ],
47 | "info" : {
48 | "version" : 1,
49 | "author" : "xcode"
50 | }
51 | }
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/Test iOS Application With CocoaPods-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIdentifier
12 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.0
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/Test iOS Application With CocoaPods-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #import
8 |
9 | #ifndef __IPHONE_3_0
10 | #warning "This project uses features only available in iOS SDK 3.0 and later."
11 | #endif
12 |
13 | #ifdef __OBJC__
14 | #import
15 | #import
16 | #endif
17 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX CocoaPods/Test iOS Application With CocoaPods/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Test iOS Application With CocoaPods
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "AppDelegate.h"
12 |
13 | int main(int argc, char * argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding.xcodeproj/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding.xcodeproj/project.xcworkspace/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Test OSX Embedding
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : NSObject
12 |
13 | @property (assign) IBOutlet NSWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Test OSX Embedding
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import
11 |
12 | @implementation AppDelegate
13 |
14 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
15 | {
16 | NSError* error = nil;
17 | NSString* evaluatedTemplate = [HBHandlebars renderTemplateString:@"Hello from {{value}}" withContext:@{ @"value" : @"Handlebars"} error:&error];
18 | NSLog(@"%@", evaluatedTemplate);
19 | }
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding/Test OSX Embedding-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSMinimumSystemVersion
26 | ${MACOSX_DEPLOYMENT_TARGET}
27 | NSHumanReadableCopyright
28 | Copyright © 2013 Fotonauts. All rights reserved.
29 | NSMainNibFile
30 | MainMenu
31 | NSPrincipalClass
32 | NSApplication
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding/Test OSX Embedding-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #ifdef __OBJC__
8 | #import
9 | #endif
10 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test OSX Embedding/Test OSX Embedding/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Test OSX Embedding
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main(int argc, const char * argv[])
12 | {
13 | return NSApplicationMain(argc, argv);
14 | }
15 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding.xcodeproj/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding.xcodeproj/project.xcworkspace/.gitignore:
--------------------------------------------------------------------------------
1 | xcuserdata
2 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Test iOS Embedding
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Test iOS Embedding
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import
11 |
12 | @implementation AppDelegate
13 |
14 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
15 | {
16 | NSString* evaluatedTemplate = [HBHandlebars renderTemplateString:@"Hello from {{value}}" withContext:@{ @"value" : @"Handlebars" }];
17 | NSLog(@"%@", evaluatedTemplate);
18 |
19 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
20 | // Override point for customization after application launch.
21 | self.window.backgroundColor = [UIColor whiteColor];
22 | [self.window makeKeyAndVisible];
23 | return YES;
24 | }
25 |
26 |
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding/Test iOS Embedding-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIdentifier
12 | com.fotonauts.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.0
25 | LSRequiresIPhoneOS
26 |
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding/Test iOS Embedding-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #import
8 |
9 | #ifndef __IPHONE_3_0
10 | #warning "This project uses features only available in iOS SDK 3.0 and later."
11 | #endif
12 |
13 | #ifdef __OBJC__
14 | #import
15 | #import
16 | #endif
17 |
--------------------------------------------------------------------------------
/src/non-unit-tests/test-embedding-in-projects/Test iOS Embedding/Test iOS Embedding/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Test iOS Embedding
4 | //
5 | // Created by Bertrand Guiheneuf on 10/14/13.
6 | // Copyright (c) 2013 Fotonauts. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "AppDelegate.h"
12 |
13 | int main(int argc, char * argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/utils/AppledocSettings.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | --project-name
6 | handlebars-objc
7 | --project-version
8 | 0.5.0
9 | --project-company
10 | Fotonauts
11 | --clean-output
12 |
13 | --keep-intermediate-files
14 |
15 | --keep-undocumented-objects
16 |
17 | --keep-undocumented-members
18 |
19 | --search-undocumented-doc
20 |
21 | --repeat-first-par
22 |
23 | --print-information-block-titles
24 |
25 | --explicit-crossref
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/utils/build_binary_distribution.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 |
4 | SCRIPT_DIR=`dirname "$0"`
5 | ROOT_DIR="$SCRIPT_DIR/../.."
6 | SOURCES_DIR="$ROOT_DIR/src"
7 | XCODE_PROJECT="$SOURCES_DIR/handlebars-objc.xcodeproj"
8 |
9 | BINARY_DISTRIBUTION_DIR="$ROOT_DIR/binaries"
10 |
11 | rm -rf "$BINARY_DISTRIBUTION_DIR"
12 |
13 | for i in ios osx; do
14 | mkdir -p "$BINARY_DISTRIBUTION_DIR/$i"
15 | done
16 |
17 | ##############################################################
18 | # Build ios framework
19 |
20 | IOS_FRAMEWORK_DIR="$BINARY_DISTRIBUTION_DIR/ios/HBHandlebars.framework"
21 |
22 | # create framework skeleton
23 | mkdir -p "$IOS_FRAMEWORK_DIR/Versions/A/Headers"
24 | /bin/ln -sfh A "$IOS_FRAMEWORK_DIR/Versions/Current"
25 | /bin/ln -sfh Versions/Current/Headers "$IOS_FRAMEWORK_DIR/Headers"
26 | /bin/ln -sfh "Versions/Current/HBHandlebars" "$IOS_FRAMEWORK_DIR/HBHandlebars"
27 |
28 | # copy headers into framework
29 | "$SCRIPT_DIR/copy_public_headers.sh" "$IOS_FRAMEWORK_DIR/Headers"
30 |
31 | # build all the variants we need
32 | BUILD_DIRECTORY="/tmp/handlebars-objc/build"
33 | rm -rf "$BUILD_DIRECTORY"
34 |
35 | echo "Building ios armv7 variants"
36 | xcodebuild -project "$XCODE_PROJECT" -target handlebars-objc-ios SYMROOT="$BUILD_DIRECTORY/symroot-ios-armv7" DSTROOT="$BUILD_DIRECTORY/dstroot-ios-armv7" OBJROOT="$BUILD_DIRECTORY/objroot-ios-armv7" SDKROOT=iphoneos6.0 ARCHS="armv7 armv7s" install > /dev/null || { echo "Failed"; exit -1; }
37 |
38 | echo "Building ios arm64 variant"
39 | xcodebuild -project "$XCODE_PROJECT" -target handlebars-objc-ios SYMROOT="$BUILD_DIRECTORY/symroot-ios-arm64" DSTROOT="$BUILD_DIRECTORY/dstroot-ios-arm64" OBJROOT="$BUILD_DIRECTORY/objroot-ios-arm64" SDKROOT=iphoneos6.0 ARCHS="arm64" install > /dev/null || { echo "Failed"; exit -1; }
40 |
41 | echo "Building ios simulator variant"
42 | xcodebuild -project "$XCODE_PROJECT" -target handlebars-objc-ios SYMROOT="$BUILD_DIRECTORY/symroot-ios-emulator" DSTROOT="$BUILD_DIRECTORY/dstroot-ios-emulator" OBJROOT="$BUILD_DIRECTORY/objroot-ios-emulator" SDKROOT=iphonesimulator6.0 ARCHS="i386 x86_64" install > /dev/null || { echo "Failed"; exit -1; }
43 |
44 |
45 | echo "Creating fat binary for ios"
46 | # mix all variants in a fat binary inside our framework skeleton
47 | lipo -create "$BUILD_DIRECTORY/objroot-ios-armv7/UninstalledProducts/libhandlebars-objc-ios.a" "$BUILD_DIRECTORY/objroot-ios-emulator/UninstalledProducts/libhandlebars-objc-ios.a" "$BUILD_DIRECTORY/objroot-ios-arm64/UninstalledProducts/libhandlebars-objc-ios.a" -output "$IOS_FRAMEWORK_DIR/HBHandlebars" || { echo "Failed"; exit -1; }
48 |
49 |
50 | ##############################################################
51 | # build osx framework
52 |
53 | echo "Building OSX framework"
54 | xcodebuild -project "$XCODE_PROJECT" -target handlebars-objc-osx SYMROOT="$BUILD_DIRECTORY/symroot-osx" DSTROOT="$BUILD_DIRECTORY/dstroot" OBJROOT="$BUILD_DIRECTORY/objroot-osx" INSTALL_PATH="/Framework" SDKROOT=macosx10.8 ARCHS="x86_64" install > /dev/null || { echo "Failed"; exit -1; }
55 |
56 | cp -RPf "$BUILD_DIRECTORY/dstroot/Framework/HBHandlebars.framework" "$BINARY_DISTRIBUTION_DIR/osx" || { echo "Failed"; exit -1; }
57 |
58 | echo "Regeneration API doc"
59 | "$SCRIPT_DIR/generate_api_doc.sh" || { echo "Failed"; exit -1; }
60 |
61 | echo "Copying documentation"
62 | cp -RPf "$ROOT_DIR/doc" "$BINARY_DISTRIBUTION_DIR/" || { echo "Failed"; exit -1; }
63 | cp -RPf "$ROOT_DIR/api_doc" "$BINARY_DISTRIBUTION_DIR/" || { echo "Failed"; exit -1; }
64 |
65 | echo "All Done!"
--------------------------------------------------------------------------------
/src/utils/convert-js-test.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | require 'json'
4 |
5 | class Hash
6 | def to_objc_literal
7 | '@{ ' + self.map {|k,v| k.to_objc_literal + ': ' + v.to_objc_literal}.join(', ') + ' }'
8 | end
9 | end
10 |
11 | class Array
12 | def to_objc_literal
13 | '@[ ' + self.map {|e| e.to_objc_literal}.join(' ,') + ' ]'
14 | end
15 | end
16 |
17 | class String
18 | def to_objc_literal
19 | '@"' + self + '"'
20 | end
21 | end
22 |
23 |
24 | class Symbol
25 | def to_objc_literal
26 | '@"' + self.to_s + '"'
27 | end
28 | end
29 |
30 | class FixNum
31 | def to_objc_literal
32 | '@' + self
33 | end
34 | end
35 |
36 | class TrueClass
37 | def to_objc_literal
38 | '@' + self
39 | end
40 | end
41 |
42 | class FalseClass
43 | def to_objc_literal
44 | '@' + self
45 | end
46 | end
47 |
48 | def replace_variable(input, variable_name)
49 | input.gsub!(/var\s+#{variable_name}\s*=\s*([^;]*);/m) { |json_hash|
50 | h = eval($1)
51 | "id #{variable_name} = #{h.to_objc_literal};"
52 | }
53 | end
54 |
55 | inp = $stdin.read
56 |
57 | # it("if", function() {
58 | inp.gsub!(/it\("([^"]*)", function\(\) \{/) { |m|
59 | val = $1
60 | cleanedUpDesc = val.gsub(/[\#\@]/, '#' => 'sharpSign', '@' => "at", '-' => 'dash')
61 | "// #{val}\n" + "- (void) test" + cleanedUpDesc.split(' ').map {|s| s.capitalize}.join('') + "\n{"
62 | }
63 |
64 | inp.gsub!(/\[hash, helpers\]/, "hash")
65 |
66 | replace_variable(inp, "string")
67 | replace_variable(inp, "out")
68 | replace_variable(inp, "byes")
69 | #replace_variable(inp, "data")
70 | replace_variable(inp, "source")
71 | replace_variable(inp, "messageString")
72 | replace_variable(inp, "dude")
73 | replace_variable(inp, "url")
74 | #replace_variable(inp, "partial")
75 |
76 | # var hash =
77 | inp.gsub!(/var\s+hash\s*=\s*([^;]*);/m) { |json_hash|
78 | h = eval($1)
79 | "id hash = #{h.to_objc_literal};"
80 | }
81 |
82 | # describe("basic context", function() {
83 | inp.gsub!(/describe\("([^"]*)\).*/, "// \\1")
84 |
85 | if true then
86 | # shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!", "pouet");
87 | inp.gsub!(/shouldCompileTo\(([^,]*),\s*([^,]*),\s*([^,]*),\s*([^,]*)\)\;/m) { |m|
88 | <<-STRING
89 | XCTAssertEqualObjects([HBHandlebars renderTemplate:@#{$1} withContext:#{$2}],
90 | @#{$3});
91 | STRING
92 | }
93 |
94 | inp.gsub!(/shouldCompileTo\(([^,]*),\s*\{([^\}]*)\},\s*([^,]*),\s*([^,]*)\)\;/m) { |m|
95 | <<-STRING
96 | XCTAssertEqualObjects([HBHandlebars renderTemplate:@#{$1} withContext:{#{$2}}],
97 | @#{$3});
98 | STRING
99 | }
100 | end
101 |
102 | inp.gsub!(/\}\)\;/, "}")
103 |
104 | puts inp
--------------------------------------------------------------------------------
/src/utils/copy_public_headers.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SCRIPT_DIR=`dirname "$0"`
4 | ROOT_DIR="$SCRIPT_DIR/../.."
5 | SRC_DIR="$ROOT_DIR/src/handlebars-objc"
6 |
7 | DEST_DIR="$1"
8 |
9 | mkdir -p "$DEST_DIR"
10 | for i in HBHandlebars.h runtime/HBTemplate.h runtime/HBExecutionContext.h runtime/HBExecutionContextDelegate.h runtime/HBEscapingFunctions.h context/HBDataContext.h context/HBHandlebarsKVCValidation.h helpers/HBHelper.h helpers/HBHelperRegistry.h helpers/HBHelperCallingInfo.h helpers/HBHelperUtils.h helpers/HBEscapedString.h partials/HBPartial.h partials/HBPartialRegistry.h errorHandling/HBErrorHandling.h ; do
11 | cp "$SRC_DIR/$i" "$DEST_DIR"
12 | done
--------------------------------------------------------------------------------
/src/utils/generate_api_doc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # You need to have appledoc installed to run this script
5 | #
6 | # 'brew install appledoc' is by far the fastest way to install it.
7 | #
8 | # Please see https://github.com/tomaz/appledoc for more details
9 | #
10 |
11 | command -v appledoc >/dev/null 2>&1 || { echo >&2 "appledoc not installed. 'brew install appledoc' is your friend. Aborting."; exit 1; }
12 |
13 | SCRIPT_DIR=`dirname $0`
14 | ROOT_DIR="$SCRIPT_DIR/../.."
15 | API_DOC_DIR="$ROOT_DIR/api_doc"
16 | SRC_DIR="$ROOT_DIR/handlebars-objc"
17 |
18 | # cleanup api doc dir
19 | rm -rf "$API_DOC_DIR"
20 |
21 | PUBLIC_HEADERS_DIR="/tmp/handlebars-objc-headers"
22 |
23 | # copy public header files to /tmp
24 | rm -rf "$PUBLIC_HEADERS_DIR"
25 | "./$SCRIPT_DIR/copy_public_headers.sh" "$PUBLIC_HEADERS_DIR"
26 |
27 | # Generate documentation
28 | mkdir -p "$API_DOC_DIR"
29 | appledoc --create-html --no-create-docset --output "$API_DOC_DIR" "$SCRIPT_DIR/AppledocSettings.plist" "$PUBLIC_HEADERS_DIR"
30 | #appledoc --no-create-html --install-docset true --index-desc "$ROOT_DIR/README.md" --output "/tmp" "$SCRIPT_DIR/AppledocSettings.plist" "$PUBLIC_HEADERS_DIR"
31 |
--------------------------------------------------------------------------------
/src/utils/generate_github_pages.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | SCRIPT_DIR=`dirname $0`
4 | ROOT_DIR="$SCRIPT_DIR/../.."
5 |
6 | git diff --quiet --exit-code
7 | if [ $? -ne 0 ]; then
8 | echo "Cannot generate static github pages if you have uncommited changes"
9 | exit -1;
10 | fi
11 |
12 | GIT_STATUS=`git status -s | grep -e "^\?\?"`
13 | if [ "$GIT_STATUS" != "" ]; then
14 | echo "cannot swith to gh-pages branch if you have untracked files in your current branch."
15 | exit -1
16 | fi
17 |
18 | current_branch=`git rev-parse --abbrev-ref HEAD`
19 | if [ "$current_branch" == "HEAD" ]; then
20 | echo "Cannot generate static github pages if you're not on a branch"
21 | exit -1;
22 | fi
23 |
24 | TMP_FOLDER="/tmp/gh_page_generation"
25 | rm -rf "$TMP_FOLDER"
26 | mkdir -p "$TMP_FOLDER"
27 |
28 | cp -RPf "$ROOT_DIR/api_doc/html" "$TMP_FOLDER/api_doc"
29 |
30 | pushd .
31 | cd "$ROOT_DIR"
32 |
33 | git checkout gh-pages || { echo "error while checkouting gh-pages branch"; exit -1; }
34 | git clean -df
35 |
36 | cp -RPf "$TMP_FOLDER/"* .
37 |
38 | GIT_STATUS=`git status -s | grep -e "^\?\?"`
39 | if [ "$GIT_STATUS" != "" ]; then
40 | echo "Cannot commit gh-pages branch if it contains untracked files. Add the new files if needed and commit your changes."
41 | echo "You are now on gh-pages branch."
42 | exit -1
43 | fi
44 |
45 | git commit -a -m "update github pages"
46 | git push
47 |
48 | git checkout "$current_branch"
49 | popd
--------------------------------------------------------------------------------
/src/utils/travis-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # travis-tests.sh
4 | # handlebars-objc
5 | #
6 | # Created by Bertrand Guiheneuf on 3/27/14.
7 | # Copyright (c) 2014 Fotonauts. All rights reserved.
8 |
9 | SCRIPT_DIR=`dirname $0`
10 | ROOT_DIR="$SCRIPT_DIR/../.."
11 |
12 | #
13 | # run xctool ourselves.
14 | #
15 | # We need to set destination to iPad, otherwise test fails with
16 | # "The run destination iPhone is not valid for Running the scheme 'handlebars-objc-ios'."
17 | #
18 | # The bug seems to be fixed in XCode 5.1
19 | #
20 |
21 | # unfortunately, -destination is only supported in xctool 0.1.14 and travis boxes have 0.1.13
22 | # so first, let's upgrade brew
23 | brew update > /dev/null
24 | # then upgrade xctool
25 | brew upgrade xctool || echo "xctool upgrade failed"
26 | # and check current version
27 | xctool --version
28 |
29 | # now launch the actual tests
30 | xctool -project "$ROOT_DIR/src/handlebars-objc.xcodeproj" -scheme handlebars-objc-ios -sdk iphonesimulator -destination name=iPad build test
31 |
--------------------------------------------------------------------------------