Skip to content

Commit

Permalink
Adding file loader
Browse files Browse the repository at this point in the history
  • Loading branch information
cohitre committed Aug 7, 2011
1 parent 20c1ec4 commit df2aeb8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/hanlon.rb
Expand Up @@ -2,6 +2,7 @@
require 'hanlon/version'
require 'hanlon/engine'
require 'hanlon/loader'
require 'hanlon/file'

module Hanlon
end
17 changes: 17 additions & 0 deletions lib/hanlon/file.rb
@@ -0,0 +1,17 @@
module Hanlon
class File
def self.load file
f = self.new "#{file}.hanlon"
f.module
end

def initialize filename
@template = ::File.read(filename)
@engine = Hanlon::Engine.new @template
end

def module
@module ||= @engine.module
end
end
end
5 changes: 5 additions & 0 deletions spec/templates/greetings.hanlon
@@ -0,0 +1,5 @@
- hanlon :greet do |name|
Hello #{name}

- hanlon :greet_user do |user|
= greet user[:name]
10 changes: 10 additions & 0 deletions spec/unit/file_spec.rb
@@ -0,0 +1,10 @@
require 'spec_helper'

describe Hanlon::File do
describe '#load' do
it 'should load a file and return a module' do
mod = Hanlon::File.load("#{File.dirname(__FILE__)}/../templates/greetings")
mod.should be_a Module
end
end
end

0 comments on commit df2aeb8

Please sign in to comment.