Skip to content

Commit 416aa5d

Browse files
authored
Merge pull request #55 from vapor/full-path
allow leaf to accept full path
2 parents 7adc344 + 8fc904a commit 416aa5d

File tree

5 files changed

+71
-57
lines changed

5 files changed

+71
-57
lines changed

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Qutheory, LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, 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,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
<p align="center"><img src="http://upload.wikimedia.org/wikipedia/commons/9/9d/Pear_Leaf.jpg" width="200"></img></p>
2-
3-
# Leaf
4-
5-
![Swift](http://img.shields.io/badge/swift-3.0-brightgreen.svg)
6-
[![Build Status](https://travis-ci.org/vapor/core.svg?branch=master)](https://travis-ci.org/vapor/leaf)
7-
[![CircleCI](https://circleci.com/gh/vapor/core.svg?style=shield)](https://circleci.com/gh/vapor/leaf)
8-
[![Code Coverage](https://codecov.io/gh/vapor/core/branch/master/graph/badge.svg)](https://codecov.io/gh/vapor/leaf)
9-
[![Codebeat](https://codebeat.co/badges/a793ad97-47e3-40d9-82cf-2aafc516ef4e)](https://codebeat.co/projects/github-com-vapor-leaf)
10-
[![Slack Status](http://vapor.team/badge.svg)](http://vapor.team)
11-
12-
Welcome to Leaf. Leaf's goal is to be a simple templating language that can make generating views easier. There's a lot of great templating languages, use what's best for you, maybe that's leaf! The goals of leaf are as follows:
13-
14-
- Small set of strictly enforced rules
15-
- Consistency
16-
- Parser first mentality
17-
- Extensibility.
18-
19-
## 📖 Documentation
20-
21-
Visit the Vapor web framework's [documentation](http://docs.vapor.codes) for instructions on how to use this package.
22-
23-
## 💧 Community
24-
25-
Join the welcoming community of fellow Vapor developers in [slack](http://vapor.team).
26-
27-
## 🔧 Compatibility
28-
29-
This package has been tested on macOS and Ubuntu.
1+
<p align="center">
2+
<img src="https://cloud.githubusercontent.com/assets/1342803/24964182/d6c85ff8-1fa0-11e7-8bd3-d11c6bbdc6dc.png" width="320" alt="Leaf">
3+
<br>
4+
<br>
5+
<a href="http://beta.docs.vapor.codes/leaf/package/">
6+
<img src="http://img.shields.io/badge/read_the-docs-92A8D1.svg" alt="Documentation">
7+
</a>
8+
<a href="http://vapor.team">
9+
<img src="http://vapor.team/badge.svg" alt="Slack Team">
10+
</a>
11+
<a href="LICENSE">
12+
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
13+
</a>
14+
<a href="https://circleci.com/gh/vapor/leaf">
15+
<img src="https://circleci.com/gh/vapor/leaf.svg?style=shield" alt="Continuous Integration">
16+
</a>
17+
<a href="https://swift.org">
18+
<img src="http://img.shields.io/badge/swift-3.1-brightgreen.svg" alt="Swift 3.1">
19+
</a>
20+
</center>

Sources/Leaf/Stem+Spawn.swift

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,31 @@ extension Stem {
1919
if name.hasPrefix("/") {
2020
name = String(name.characters.dropFirst())
2121
}
22-
22+
return try spawnLeaf(at: workingDirectory + name)
23+
}
24+
25+
public func spawnLeaf(at path: String) throws -> Leaf {
26+
if let existing = cache?[path] {
27+
return existing
28+
}
29+
30+
let leaf: Leaf
31+
2332
// non-leaf document. rendered as pure bytes
24-
if name.characters.contains("."), !name.hasSuffix(".leaf") {
25-
if let existing = cache?[name] { return existing }
26-
let path = workingDirectory + name
33+
if path.components(separatedBy: "/").last?.contains(".") == true, !path.hasSuffix(".leaf") {
2734
let bytes = try Bytes.load(path: path)
2835
let component = Leaf.Component.raw(bytes)
29-
let leaf = Leaf(raw: bytes.makeString(), components: [component])
30-
cache(leaf, named: name)
31-
return leaf
36+
leaf = Leaf(raw: bytes.makeString(), components: [component])
37+
} else {
38+
// add suffix if necessary
39+
var path = path
40+
path = path.finished(with: SUFFIX)
41+
42+
let raw = try Bytes.load(path: path)
43+
leaf = try spawnLeaf(raw: raw)
3244
}
33-
34-
name = name.finished(with: SUFFIX)
35-
36-
// add suffix if necessary
37-
if let existing = cache?[name] { return existing }
38-
39-
let path = workingDirectory + name
40-
let raw = try Bytes.load(path: path)
41-
let leaf = try spawnLeaf(raw: raw)
42-
cache(leaf, named: name)
45+
46+
cache(leaf, named: path)
4347
return leaf
4448
}
4549

circle.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
dependencies:
2+
override:
3+
- eval "$(curl -sL https://apt.vapor.sh)"
4+
- sudo apt-get install vapor
5+
- sudo chmod -R a+rx /usr/
16
test:
27
override:
3-
- eval "$(curl -sL swift.vapor.sh/ci-3.1)"
8+
- swift build
9+
- swift build -c release
10+
- swift test
11+

0 commit comments

Comments
 (0)