Skip to content

Commit

Permalink
Merge pull request #55 from vapor/full-path
Browse files Browse the repository at this point in the history
allow leaf to accept full path
  • Loading branch information
tanner0101 authored Apr 12, 2017
2 parents 7adc344 + 8fc904a commit 416aa5d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 57 deletions.
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Qutheory, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 20 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
<p align="center"><img src="http://upload.wikimedia.org/wikipedia/commons/9/9d/Pear_Leaf.jpg" width="200"></img></p>

# Leaf

![Swift](http://img.shields.io/badge/swift-3.0-brightgreen.svg)
[![Build Status](https://travis-ci.org/vapor/core.svg?branch=master)](https://travis-ci.org/vapor/leaf)
[![CircleCI](https://circleci.com/gh/vapor/core.svg?style=shield)](https://circleci.com/gh/vapor/leaf)
[![Code Coverage](https://codecov.io/gh/vapor/core/branch/master/graph/badge.svg)](https://codecov.io/gh/vapor/leaf)
[![Codebeat](https://codebeat.co/badges/a793ad97-47e3-40d9-82cf-2aafc516ef4e)](https://codebeat.co/projects/github-com-vapor-leaf)
[![Slack Status](http://vapor.team/badge.svg)](http://vapor.team)

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:

- Small set of strictly enforced rules
- Consistency
- Parser first mentality
- Extensibility.

## 📖 Documentation

Visit the Vapor web framework's [documentation](http://docs.vapor.codes) for instructions on how to use this package.

## 💧 Community

Join the welcoming community of fellow Vapor developers in [slack](http://vapor.team).

## 🔧 Compatibility

This package has been tested on macOS and Ubuntu.
<p align="center">
<img src="https://cloud.githubusercontent.com/assets/1342803/24964182/d6c85ff8-1fa0-11e7-8bd3-d11c6bbdc6dc.png" width="320" alt="Leaf">
<br>
<br>
<a href="http://beta.docs.vapor.codes/leaf/package/">
<img src="http://img.shields.io/badge/read_the-docs-92A8D1.svg" alt="Documentation">
</a>
<a href="http://vapor.team">
<img src="http://vapor.team/badge.svg" alt="Slack Team">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://circleci.com/gh/vapor/leaf">
<img src="https://circleci.com/gh/vapor/leaf.svg?style=shield" alt="Continuous Integration">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-3.1-brightgreen.svg" alt="Swift 3.1">
</a>
</center>
38 changes: 21 additions & 17 deletions Sources/Leaf/Stem+Spawn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,31 @@ extension Stem {
if name.hasPrefix("/") {
name = String(name.characters.dropFirst())
}

return try spawnLeaf(at: workingDirectory + name)
}

public func spawnLeaf(at path: String) throws -> Leaf {
if let existing = cache?[path] {
return existing
}

let leaf: Leaf

// non-leaf document. rendered as pure bytes
if name.characters.contains("."), !name.hasSuffix(".leaf") {
if let existing = cache?[name] { return existing }
let path = workingDirectory + name
if path.components(separatedBy: "/").last?.contains(".") == true, !path.hasSuffix(".leaf") {
let bytes = try Bytes.load(path: path)
let component = Leaf.Component.raw(bytes)
let leaf = Leaf(raw: bytes.makeString(), components: [component])
cache(leaf, named: name)
return leaf
leaf = Leaf(raw: bytes.makeString(), components: [component])
} else {
// add suffix if necessary
var path = path
path = path.finished(with: SUFFIX)

let raw = try Bytes.load(path: path)
leaf = try spawnLeaf(raw: raw)
}

name = name.finished(with: SUFFIX)

// add suffix if necessary
if let existing = cache?[name] { return existing }

let path = workingDirectory + name
let raw = try Bytes.load(path: path)
let leaf = try spawnLeaf(raw: raw)
cache(leaf, named: name)

cache(leaf, named: path)
return leaf
}

Expand Down
10 changes: 9 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
dependencies:
override:
- eval "$(curl -sL https://apt.vapor.sh)"
- sudo apt-get install vapor
- sudo chmod -R a+rx /usr/
test:
override:
- eval "$(curl -sL swift.vapor.sh/ci-3.1)"
- swift build
- swift build -c release
- swift test

0 comments on commit 416aa5d

Please sign in to comment.