Skip to content

Commit

Permalink
docs: update metadata and readme about source annotation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofzablocki committed Dec 15, 2016
1 parent e048a0d commit 7a1befc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ In those scenarios usually **compiler won't generate the error for you**, which
_**Sourcery** is a tool that scans your source code, applies your personal templates and generates Swift code for you, allowing you to use meta-programming techniques to save time and decrease potential mistakes._

- Scans your project code.
- [Adds code annotations](#source-annotations), think attributes like in Rust
- Allows your templates to access information about project types.
- Generates swift code.
- **Immediate feedback:** Sourcery features built-in daemon support, allowing you to write your templates in real-time side-by-side with generated code.
Expand Down Expand Up @@ -196,6 +197,7 @@ There are multiple ways to access your types:
For each type you can access following properties:

- `name`
- `kind` <- convience accessor that will contain one of `enum`, `class`, `struct`, `protocol`
- `localName` <- name within parent scope
- `staticVariables` <- list of static variables
- `variables` <- list of instance variables
Expand All @@ -204,6 +206,7 @@ For each type you can access following properties:
- `inheritedTypes` <- list of type names that this type implements / inherits
- `containedTypes` <- list of types contained within this type
- `parentName` <- list of parent type (for contained ones)
- `annotations` <- dictionary with configured [annotations](#source-annotations)

**Enum** types builts on top of regular types and adds:

Expand Down Expand Up @@ -231,6 +234,41 @@ For each type you can access following properties:
- `isStatic` <- whether is static variable
- `readAccess` <- what is the protection access for reading?
- `writeAccess` <- what is the protection access for writing?
- `annotations` <- dictionary with configured [annotations](#source-annotations)


## Source Annotations

Sourcery supports annotating your classes and variables with special annotations, similar how attributes work in Rust / Java

```swift
/// sourcery: skipPersistence
/// Some documentation comment
/// sourcery: anotherAnnotation = 232, yetAnotherAnnotation = "value"
/// Documentation
var precomputedHash: Int
```

#### Features:

- Multiple annotations can occur on the same line
- Multiline annotations are supported
- You can interleave annotations with documentation
- Sourcery will scan all `sourcery:` annotations in the given comment block above the source until first non comment/doc line

#### Format:

- simple entry, e.g. `sourcery: skipPersistence`
- key = number, e.g. `sourcery: another = 123`
- key = string, e.g. `sourcery: jsonKey = "json_key"`

#### Accessing in templates:

```swift
{% ifnot variable.annotations.skipPersistence %}
var local{{ variable.name|capitalize }} = json["{{ variable.annotations.jsonKey }}"] as? {{ variable.typeName }}
{% endif %}
```

# Installing

Expand Down
2 changes: 1 addition & 1 deletion Sourcery.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Sourcery"
s.version = "0.3.3"
s.version = "0.3.5"
s.summary = "A tool that brings meta-programming to Swift, allowing you to code generate Swift code."

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Sourcery/Sourcery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class SourceryTemplate: Template {
/// If you specify templatePath as a folder, it will create a Generated[TemplateName].swift file
/// If you specify templatePath as specific file, it will put all generated results into that single file
public class Sourcery {
public static let version: String = inUnitTests ? "Major.Minor.Patch" : "0.3.3"
public static let version: String = inUnitTests ? "Major.Minor.Patch" : "0.3.5"
public static let generationMarker: String = "// Generated using Sourcery"

let verbose: Bool
Expand Down

0 comments on commit 7a1befc

Please sign in to comment.