Skip to content

Commit

Permalink
Old code example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 26, 2024
1 parent 4978274 commit 8467530
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/trenni-3.9/gems.locked
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
GEM
remote: https://rubygems.org/
specs:
trenni (3.14.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
trenni (~> 3.9)

BUNDLED WITH
2.5.5
3 changes: 3 additions & 0 deletions examples/trenni-3.9/gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "trenni", "~> 3.9"
31 changes: 31 additions & 0 deletions examples/trenni-3.9/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby

require 'trenni'
require 'trenni/version'

class Formatter
def title_for(options)
options[:title]
end

def value_for(options)
options[:value]
end

def row(options = {}, &block)
Trenni::Builder.fragment do |builder|
builder.inline(:dt) { builder.text title_for(options) }

if block_given?
builder.inline(:dd) { builder.capture(self, &block) }
else
builder.inline(:dd) { builder.text value_for(options) }
end
end >> block
end
end

puts "Trenni version: #{Trenni::VERSION}"

template = Trenni::Template.load_file('test.trenni')
puts template.to_string(binding)
13 changes: 13 additions & 0 deletions examples/trenni-3.9/test.trenni
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?r
f = Formatter.new
?>

# Test Interpolation
#{f.row :title => 'Test title', :value => "Test value"}

# Test Tag
<?r f.row title: 'Title Test' do ?>
<a href="test-link">Test Link</a>
<?r end ?>

# Done
32 changes: 32 additions & 0 deletions examples/xrb/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby

require_relative 'lib/xrb'

class Formatter
def title_for(options)
options[:title]
end

def value_for(options)
options[:value]
end

def row(options = {}, &block)
XRB::Builder.fragment do |builder|
builder.inline(:dt) { builder.text title_for(options) }

if block_given?
binding.irb
builder.inline(:dd) { builder.capture(self, &block) }
else
builder.inline(:dd) { builder.text value_for(options) }
end
end
end
end

template = XRB::Template.load_file('test.xrb')

binding.irb

puts template.to_string(binding)
13 changes: 13 additions & 0 deletions examples/xrb/test.xrb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?r
f = Formatter.new
?>

# Test Interpolation
#{f.row :title => 'Test title', :value => "Test value"}

# Test Tag
<?r f.row title: 'Title Test' do ?>
<a href="test-link">Test Link</a>
<?r end ?>

# Done

0 comments on commit 8467530

Please sign in to comment.