<commit_before>
use Renderable;
use context::Context;
use token::Token;
use LiquidOptions;
use template::Template;
use parser;
use lexer;
use error::{Result, Error};

use std::fs::File;
use std::io::Read;
use std::path::Path;

struct Include {
    partial: Template,
}

impl Renderable for Include {
    fn render(&self, mut context: &mut Context) -> Result<Option<String>> {
        self.partial.render(&mut context)
    }
}

fn parse_partial<P: AsRef<Path>>(path: P, options: &LiquidOptions) -> Result<Template> {
    let path = path.as_ref();

    // check if file exists
    if !path.exists() {
        return Error::parser_msg(&format!("{:?} does not exist", path));
    }

    let mut file = try!(File::open(path));

    let mut content = String::new();
    try!(file.read_to_string(&mut content));

    let tokens = try!(lexer::tokenize(&content));
    parser::parse(&tokens, &options).map(Template::new)
}

pub fn include_tag(_tag_name: &str,
                   arguments: &[Token],
                   options: &LiquidOptions)
                   -> Result<Box<Renderable>> {
    let mut args = arguments.iter();

    let path = match args.next() {
        Some(&Token::Identifier(ref path)) => path,
        arg => return Error::parser("Identifier", arg),
    };

    Ok(Box::new(Include { partial: try!(parse_partial(&path, &options)) }))
}

#[cfg(test)]
mod test {
    use context::Context;
    use Renderable;
    use parse;
    use error::Error;

    #[test]
    fn include_tag() {
        let text = "{% include tests/fixtures/additional/default.liquid %}";
        let template = parse(text, Default::default()).unwrap();

        let mut context = Context::new();
        assert_eq!(template.render(&mut context).unwrap(),
                   Some("hello, world!\n".to_owned()));
    }

    #[test]
    fn no_file() {
        let text = "{% include file_does_not_exsist.liquid %}";
        let output = parse(text, Default::default());

        assert!(output.is_err());
        if let Err(Error::Parser(val)) = output {
            assert_eq!(format!("{}", val),
                       "\"file_does_not_exsist.liquid\" does not exist".to_owned());
        } else {
            assert!(false);
        }
    }
}<commit_msg>fixed spelling mistake<commit_after>
use Renderable;
use context::Context;
use token::Token;
use LiquidOptions;
use template::Template;
use parser;
use lexer;
use error::{Result, Error};

use std::fs::File;
use std::io::Read;
use std::path::Path;

struct Include {
    partial: Template,
}

impl Renderable for Include {
    fn render(&self, mut context: &mut Context) -> Result<Option<String>> {
        self.partial.render(&mut context)
    }
}

fn parse_partial<P: AsRef<Path>>(path: P, options: &LiquidOptions) -> Result<Template> {
    let path = path.as_ref();

    // check if file exists
    if !path.exists() {
        return Error::parser_msg(&format!("{:?} does not exist", path));
    }

    let mut file = try!(File::open(path));

    let mut content = String::new();
    try!(file.read_to_string(&mut content));

    let tokens = try!(lexer::tokenize(&content));
    parser::parse(&tokens, &options).map(Template::new)
}

pub fn include_tag(_tag_name: &str,
                   arguments: &[Token],
                   options: &LiquidOptions)
                   -> Result<Box<Renderable>> {
    let mut args = arguments.iter();

    let path = match args.next() {
        Some(&Token::Identifier(ref path)) => path,
        arg => return Error::parser("Identifier", arg),
    };

    Ok(Box::new(Include { partial: try!(parse_partial(&path, &options)) }))
}

#[cfg(test)]
mod test {
    use context::Context;
    use Renderable;
    use parse;
    use error::Error;

    #[test]
    fn include_tag() {
        let text = "{% include tests/fixtures/additional/default.liquid %}";
        let template = parse(text, Default::default()).unwrap();

        let mut context = Context::new();
        assert_eq!(template.render(&mut context).unwrap(),
                   Some("hello, world!\n".to_owned()));
    }

    #[test]
    fn no_file() {
        let text = "{% include file_does_not_exist.liquid %}";
        let output = parse(text, Default::default());

        assert!(output.is_err());
        if let Err(Error::Parser(val)) = output {
            assert_eq!(format!("{}", val),
                       "\"file_does_not_exist.liquid\" does not exist".to_owned());
        } else {
            assert!(false);
        }
    }
}
{'fraction_non_alphanumeric': 0.16335639366212898, 'fraction_numerical': 0.0, 'mean_word_length': 2.7886728655959425, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7114746', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1357, 'n_words': 322}