Home > ht

ht

Ht is a project mainly written in Ruby, based on the MIT license.

Cascading Hash Templates for Ruby

= HT

Simple templating for ruby hashes

= Example Usage

cascade = HT::Cascade.new(:my_cascade) do
  base do |data|
    set_value :d, "abc"
  end

  layer :path_share do |data|
    set :a, data[:a] # set => set_value
    s :b, data[:b] # s => set_value
  end

  layer :path_1_mid, :path_share do |data|
    set_value :a, data[:b]
  end

  layer :path_2_mid, :path_share do |data|
    set_value get_value(:a), :a
    set_value get(:b), :b # get => get_value
  end

  layer :path_1_all, :path_1_mid do |data|
    set_value :b, data[:a]
    set_value :c, get_value(:a) + g(:b) # g => get_value
  end

  layer :path_2_all, :path_2_mid do |data|
    set_value :c, data[:a] * data[:b]
  end
end

>> builder = HT::Builder.new
=> #<HT::Builder ...>

>> data = {:a => 1, :b => 2}
{:a => 1, :b => 2}

>> builder.run(cascade, data, :path_1_all)
=> {:d=>"abc", :a=>2, :b=>1, :c=>3}

>> builder.run(cascade, data, :path_1_mid)
=> {:d=>"abc", :a=>2, :b=>2}

>> builder.run(cascade, data, :path_2_all)
=> {:d=>"abc", :a=>1, :b=>2, 1=>:a, 2=>:b, :c=>2}

>> builder.run(cascade, data, :path_2_mid)
=> {:d=>"abc", :a=>1, :b=>2, 1=>:a, 2=>:b}

>> builder.run(cascade, data, :path_share)
=> {:d=>"abc", :a=>1, :b=>2}

>> builder.run(cascade, data, :base)
=> {:d => "abc"}

== Contributing to HT

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Roadmap

  • Cascade Improvements

    • Allow cascades to be "reopened" like a ruby class and modified (DONE)
    • Delete layer by name
    • Update layer dependency by name without having to pass it the existing block
    • Cascade mixins? Mix cascades into each other? or have seperate structure?
    • Give cascade names a purpose
    • Global cascade hash/table (DONE)
    • Build by name instead of cascade instance (DONE)
    • Aide in opening existing templates and modifying them (DONE)
      • calling new with the name of an existing template can modify or overwrite (DONE)
  • Build Process Improvements

    • skip layer (e.g. skip) (DONE)
    • halt/stop (e.g. stop execution before or after this layer or on call) (DONE)
    • priority/freeze (e.g. mark a value is no longer able to be overwritten during build)
    • better support for nested hashes in results (? maybe a-la mongodb)

== Copyright

Copyright (c) 2010 Jordan West. See LICENSE.txt for further details.