Skip to content

Commit

Permalink
Merge pull request #42 from jjcomer/dep-upgrade
Browse files Browse the repository at this point in the history
Dep upgrade
  • Loading branch information
jjcomer authored Mar 17, 2020
2 parents 5dd85fa + b0ca289 commit 5fd4fd0
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 75 deletions.
33 changes: 11 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ doc = false

[package]
name = 'hogan'
version = '0.7.3'
authors = ['Jonathan Morley <jmorley@cvent.com>']
version = '0.7.4'
authors = [
'Jonathan Morley <jmorley@cvent.com>',
'Josh Comer <jcomer@cvent.com>',
]
edition = '2018'

[dependencies]
failure = '0.1'
git2 = '0.10'
git2 = '0.12'
lru_time_cache = '0.9.0'
handlebars = '2'
itertools = '0.8'
handlebars = '3'
itertools = '0.9'
json-patch = '0.2'
log = '0.4'
serde_derive = '1'
serde_json = '1'
shellexpand = '1'
shellexpand = '2.0.0'
stderrlog = '0.4'
structopt = '0.3'
tempfile = '3'
Expand Down
5 changes: 4 additions & 1 deletion ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ main() {
;;
x86_64-apple-ios)
rustup target install x86_64-apple-ios
# Clean up mac installation
cargo clean
;;
esac

cargo install cross --force
# Fix cross version as higher stopped including openssl as a dep
cargo install --version 0.1.16 cross
}

main
6 changes: 3 additions & 3 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ set -ex

# TODO This is the "test phase", tweak it as you see fit
main() {
cross build --target $TARGET
#cross build --target $TARGET
cross build --target $TARGET --release

if [ ! -z $DISABLE_TESTS ]; then
return
fi

cross test --target $TARGET
#cross test --target $TARGET
cross test --target $TARGET --release

cross run --target $TARGET -- --help
#cross run --target $TARGET -- --help
cross run --target $TARGET --release -- --help
}

Expand Down
4 changes: 2 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ pub fn fetch(

let mut fo = FetchOptions::new();
fo.remote_callbacks(cb);
remote.download(&[], Some(&mut fo))?;
remote.download(&Vec::<String>::new(), Some(&mut fo))?;

remote.disconnect();
remote.disconnect()?;

remote.update_tips(None, true, AutotagOption::Unspecified, None)?;

Expand Down
36 changes: 19 additions & 17 deletions src/transform/helper_comma_delimited_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pub struct CommaDelimitedListHelper;
impl HelperDef for CommaDelimitedListHelper {
// Change an array of items into a comma seperated list with formatting
// Usage: {{#comma-list array}}{{elementAttribute}}:{{attribute2}}{{/comma-list}}
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Handlebars,
ctx: &Context,
rc: &mut RenderContext<'reg>,
ctx: &'ctx Context,
rc: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let value = h
Expand All @@ -23,28 +23,30 @@ impl HelperDef for CommaDelimitedListHelper {
match h.template() {
Some(template) => match *value.value() {
Json::Array(ref list) => {
let len = list.len();

let mut render_list = Vec::new();

for (i, item) in list.iter().enumerate().take(len) {
let mut local_rc = rc.derive();

if let Some(inner_path) = value.path() {
let new_path =
format!("{}/{}/[{}]", local_rc.get_path(), inner_path, i);
local_rc.set_path(new_path.clone());
for (i, item) in list.iter().enumerate() {
let mut local_rc = rc.clone();
let block_rc = local_rc.block_mut().unwrap();
if let Some(inner_path) = value.context_path() {
let block_path = block_rc.base_path_mut();
block_path.append(&mut inner_path.to_owned());
block_path.push(i.to_string());
}

if let Some(block_param) = h.block_param() {
let mut new_block = BlockContext::new();
let mut block_params = BlockParams::new();
block_params.add_value(&block_param.to_string(), to_json(item))?;
local_rc.push_block_context(block_params)?;
}
let param = block_param.to_owned();
block_params.add_value(&param, to_json(item))?;
new_block.set_block_params(block_params);
local_rc.push_block(new_block);

render_list.push(template.renders(r, ctx, &mut local_rc)?);
render_list.push(template.renders(r, ctx, &mut local_rc)?);
} else {
render_list.push(template.renders(r, ctx, &mut local_rc)?);
}
}

out.write(&join(&render_list, ","))?;

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_equal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use handlebars::*;
pub struct EqualHelper;

impl HelperDef for EqualHelper {
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Handlebars,
ctx: &Context,
rc: &mut RenderContext<'reg>,
ctx: &'ctx Context,
rc: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let lvalue = h
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_lowercase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use serde_json::value::Value as Json;
pub struct LowercaseHelper;

impl HelperDef for LowercaseHelper {
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
_: &'reg Handlebars,
_: &Context,
_: &mut RenderContext<'reg>,
_: &'ctx Context,
_: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let value = h
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use handlebars::*;
pub struct OrHelper;

impl HelperDef for OrHelper {
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
r: &'reg Handlebars,
ctx: &Context,
rc: &mut RenderContext<'reg>,
ctx: &'ctx Context,
rc: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
if h.params().len() < 2 {
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_url_add_slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub struct UrlAddSlashHelper;

impl HelperDef for UrlAddSlashHelper {
// Adds the trailing slashes on an endpoint
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
_: &'reg Handlebars,
_: &Context,
_: &mut RenderContext<'reg>,
_: &'ctx Context,
_: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let value = h
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_url_rm_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub struct UrlRmPathHelper;

impl HelperDef for UrlRmPathHelper {
// Removes the last slash plus content to the end of the string
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
_: &'reg Handlebars,
_: &Context,
_: &mut RenderContext<'reg>,
_: &'ctx Context,
_: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let value = h
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_url_rm_slash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub struct UrlRmSlashHelper;

impl HelperDef for UrlRmSlashHelper {
// Removes the trailing slash on an endpoint
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
_: &'reg Handlebars,
_: &Context,
_: &mut RenderContext<'reg>,
_: &'ctx Context,
_: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let value = h
Expand Down
6 changes: 3 additions & 3 deletions src/transform/helper_yaml_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub struct YamlStringHelper;

impl HelperDef for YamlStringHelper {
// Escapes strings to that they can be safely used inside yaml (And JSON for that matter).
fn call<'reg: 'rc, 'rc>(
fn call<'reg: 'rc, 'rc, 'ctx>(
&self,
h: &Helper<'reg, 'rc>,
_: &'reg Handlebars,
_: &Context,
_: &mut RenderContext<'reg>,
_: &'ctx Context,
_: &mut RenderContext<'reg, 'ctx>,
out: &mut dyn Output,
) -> HelperResult {
let value = h
Expand Down
13 changes: 10 additions & 3 deletions src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use self::helper_url_rm_path::UrlRmPathHelper;
use self::helper_url_rm_slash::UrlRmSlashHelper;
use self::helper_yaml_string::YamlStringHelper;

pub fn handlebars(strict: bool) -> Handlebars {
pub fn handlebars<'a>(strict: bool) -> Handlebars<'a> {
let mut handlebars = Handlebars::new();
handlebars.set_strict_mode(strict);
handlebars.register_helper("comma-list", Box::new(CommaDelimitedListHelper));
Expand Down Expand Up @@ -57,9 +57,16 @@ mod test {
assert_eq!(&null_rendered.unwrap(), "");
}

pub(crate) fn test_error_against_configs(handlebars: &Handlebars, template: &str, expected: &str) {
pub(crate) fn test_error_against_configs(
handlebars: &Handlebars,
template: &str,
expected: &str,
) {
let config_rendered = handlebars.render_template(template, &config_fixture());
assert!(!config_rendered.is_ok());
assert_eq!(&config_rendered.unwrap_err().as_render_error().unwrap().desc, expected);
assert_eq!(
&config_rendered.unwrap_err().as_render_error().unwrap().desc,
expected
);
}
}

0 comments on commit 5fd4fd0

Please sign in to comment.