fun_with_templates 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +15 -0
  2. data/.document +5 -0
  3. data/CHANGELOG.markdown +6 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +67 -0
  7. data/Rakefile +45 -0
  8. data/VERSION +1 -0
  9. data/lib/fun_with/core_extensions/kernel.rb +18 -0
  10. data/lib/fun_with/templates/directory_builder.rb +36 -0
  11. data/lib/fun_with/templates/filename_var_data.rb +42 -0
  12. data/lib/fun_with/templates/template_evaluator.rb +307 -0
  13. data/lib/fun_with_templates.rb +4 -0
  14. data/test/helper.rb +57 -0
  15. data/test/templates/00/a.rb.template +7 -0
  16. data/test/templates/00/dir/subdir/style.css +4 -0
  17. data/test/templates/00/seqfiles/page%0000i%.html.template +12 -0
  18. data/test/templates/00/seqfiles/page%j%.html.template +12 -0
  19. data/test/templates/00/seqfiles/page_about_%critter_name%.html.template +15 -0
  20. data/test/templates/01/%string.length%/%string%-%string.length%.nontemplate +1 -0
  21. data/test/templates/01/%string.length%/%string%-%string.length%.txt.template +1 -0
  22. data/test/templates/02/%class%.rb.template +6 -0
  23. data/test/templates/03/coordinates.%i%-%j%-%k%.html.template +14 -0
  24. data/test/templates/03/dir%0000i%/dir%0000j%/file%0000k%.py.template +1 -0
  25. data/test/templates/03/index.html.template +22 -0
  26. data/test/templates/epf/book/afterword.markdown +4 -0
  27. data/test/templates/epf/book/chapter-%0000chapter%.markdown.template +4 -0
  28. data/test/templates/epf/book/cover.xhtml.template +13 -0
  29. data/test/templates/epf/book/foreword.markdown +6 -0
  30. data/test/templates/epf/book/images/cover.png +0 -0
  31. data/test/templates/epf/book/stylesheets/stylesheet.css +2 -0
  32. data/test/templates/epf/book/title_page.markdown.template +5 -0
  33. data/test/templates/epf/notes/character.%character.name_for_file%.markdown.template +15 -0
  34. data/test/templates/epf/notes/images/cover.png +0 -0
  35. data/test/templates/epf/notes/stylesheets/stylesheet.css +2 -0
  36. data/test/templates/epf/settings/actions/local_action.rb.example +14 -0
  37. data/test/templates/epf/settings/config.rb.template +52 -0
  38. data/test/templates/epf/settings/htmlizers.rb +83 -0
  39. data/test/templates/epf/settings/wordcount.template +6 -0
  40. data/test/test_directory_builder.rb +24 -0
  41. data/test/test_filename_var_data.rb +51 -0
  42. data/test/test_fun_with_templates.rb +21 -0
  43. data/test/test_parse_filename_vars.rb +25 -0
  44. data/test/test_string_templates.rb +14 -0
  45. data/test/test_write_example_templates.rb +149 -0
  46. metadata +202 -0
@@ -0,0 +1,4 @@
1
+ require 'fun_with_gems'
2
+ require 'erb'
3
+
4
+ FunWith::Gems.make_gem_fun( "FunWith::Templates" )
data/test/helper.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'debugger'
4
+
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+
13
+ require 'shoulda'
14
+ require 'fun_with_templates'
15
+ require 'fun_with_testing'
16
+
17
+ class FunWith::Templates::TestCase < FunWith::Testing::TestCase
18
+ gem_to_test( FunWith::Templates )
19
+
20
+ FunWith::Templates.gem_test_mode = true
21
+ FunWith::Templates.gem_verbose = false
22
+
23
+ # include FunWith::Templates
24
+ include FunWith::Testing::Assertions::Basics
25
+ include FunWith::Testing::Assertions::FunWithFiles
26
+
27
+ def epf_template_vars( overrides = {} )
28
+ vars = {
29
+ :book => {
30
+ :title => "The Dawning of the Elluini",
31
+ :author => "Manchester Von Spittleman",
32
+ :license => "Creative Commons",
33
+ :publisher => "PUBLISHER NAME",
34
+ :original_publication => "2014-01-01"
35
+ },
36
+
37
+ :character => {
38
+ :name => "Wilford Brimley",
39
+ :name_for_file => "wilford_brimley",
40
+ :age => "Older than time itself",
41
+ :summary => "The Faceless Old Man Who Secretly Lives In Your Home",
42
+ :description => "Gentle, wizened, concerned about your bowel movements."
43
+ },
44
+
45
+ :chapter => (1..20),
46
+
47
+ :git => {
48
+ :repo => "/home/barry/git/the_dawning_of_the_elluini.epubforge.git",
49
+ :remote_host => "m.slashdot.org",
50
+ :remote_user => "barry",
51
+ :repo_id => "36ce67680bbf6fc4d64741cbc3980fa5"
52
+ }
53
+ }
54
+
55
+ vars.merge( overrides )
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ module <%= @module %>
2
+ class <%= @class %>
3
+ def <%= @method %>( <%= @args.join(", ") %> )
4
+ <%= @args.join( " * " ) %>
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ h1.title{
2
+ font-size: 18pt;
3
+ font-weight: bold;
4
+ }
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <title>This is page <%= @i %></title>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Page <%= @i %></h1>
11
+ </body>
12
+ </html>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <title>This is page <%= @j %></title>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Page <%= @j %></h1>
11
+ </body>
12
+ </html>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <title>Behold the mighty <%= @critter_name %>!</title>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>This page is about the <%= @critter_name %></h1>
11
+
12
+ <% critter = @critters[@critter_name] %>
13
+ <p>The <%= @critter_name %> is <%= critter[:attributes][0] %> and <%= critter[:attributes][1] %></p>
14
+ </body>
15
+ </html>
@@ -0,0 +1 @@
1
+ Some strings have some lengths. But who can know for sure?
@@ -0,0 +1 @@
1
+ string <%= @string %> has length <%= @string.length %>
@@ -0,0 +1,6 @@
1
+ class <%= @class.camelize %>
2
+ <% for method in @methods %>
3
+ def <%= method[:name] %>(<%= method[:args] %>)
4
+ end
5
+ <% end %>
6
+ end
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <title>This is page for sector (<%= @i %>, <%= @j %>, <%= @k %>)</title>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>This is page for sector (<%= @i %>, <%= @j %>, <%= @k %>)</h1>
11
+
12
+ <p>This sector is full of things.</p>
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ <%= @i %>-<%= @j %>-<%= @k %>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml">
5
+ <head>
6
+ <title>Links to all sectors</title>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Sectors</h1>
11
+
12
+ <ul>
13
+ <% for i in @i %>
14
+ <% for j in @j %>
15
+ <% for k in @k %>
16
+ <li><a href="coordinates.<%= i %>-<%= j %>-<%= k %>.html">Sector (<%= i %>, <%= j %>, <%= k %>)</a></li>
17
+ <% end %>
18
+ <% end %>
19
+ <% end %>
20
+ </ul>
21
+ </body>
22
+ </html>
@@ -0,0 +1,4 @@
1
+ You made it all the way through the book
2
+ ========================================
3
+
4
+ When I started writing this book, I had no idea someone would make it all the way to the end. Well done. Now go find something else to do.
@@ -0,0 +1,4 @@
1
+ Chapter <%= @chapter %>
2
+ ========<%= "=" * @chapter.to_s.length %>
3
+
4
+
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
+
5
+ <html xmlns="http://www.w3.org/1999/xhtml">
6
+ <head>
7
+ <title><%= @book[:title] %>, by <%= @book[:author] %></title>
8
+ </head>
9
+
10
+ <body>
11
+ <p><img class="cover" alt="<%= @book[:title] %>, by <%= @book[:author] %>" src="<%= @book[:cover].nil? ? "../Images/cover.jpg" : @book[:cover].path %>" /></p>
12
+ </body>
13
+ </html>
@@ -0,0 +1,6 @@
1
+ Foreword
2
+ ========
3
+
4
+ I dedicate the book to me, without whom none of this would be written.
5
+
6
+ And to my cat, for finally getting off the keyboard and letting me type.
@@ -0,0 +1,2 @@
1
+ div#epubforge_scene_description{ display: none }
2
+
@@ -0,0 +1,5 @@
1
+ <%= @book[:title] %>
2
+ <%= "=" * (@book[:title] || "===").length %>
3
+
4
+ by <%= @book[:author] %>
5
+
@@ -0,0 +1,15 @@
1
+ <%= @character[:name] %>
2
+ <%= "=" * (@character[:name] || "").length %>
3
+
4
+ Summary
5
+ -------
6
+
7
+ <%= @character[:summary] %>
8
+
9
+ Description
10
+ -----------
11
+
12
+ Age: <%= @character[:age] %>
13
+
14
+ <%= @character[:description] %>
15
+
@@ -0,0 +1,2 @@
1
+ div#epubforge_scene_description{ display: none }
2
+
@@ -0,0 +1,14 @@
1
+ module EpubForge
2
+ module Action
3
+ class <%= @class_name %> < ThorAction
4
+
5
+ <% for action in @actions %>
6
+ desc( "<%= @slug %>:<%= action %>", "do action <%= action %>" )
7
+ def <%= action %>( project, *args )
8
+ puts "Do action <%= action %> to your project."
9
+ end
10
+
11
+ <% end %>
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ # Used by epubforge.
2
+ metadata do
3
+ name "<%= @book[:title] || "My Book" %>" # The title of the book
4
+ author "<%= @book[:author] || "Author" %>" # Your moniker. Your Nom de Plume. The thing people say to get your attention.
5
+ license "<%= @book[:license] || "All Rights Reserved" %>"
6
+ publisher "<%= @book[:publisher] || 'My Publisher' %>"
7
+ original_publication "<%= @book[:original_publication] || Time.now.strftime('%Y-%m-%d') %>" # The year this work was first published
8
+ end
9
+
10
+ filename "<%= (@book[:title] || "my_book").epf_underscorize %>" # The default filename for your ebook (no extension).
11
+
12
+ <% if @git %>
13
+ ############### GOT GIT? #####################################
14
+ git do
15
+ repo_folder "<%= @git[:repo] %>"
16
+ remote_host "<%= @git[:host] %>"
17
+ remote_user "<%= @git[:user] %>"
18
+ repo_id "<%= @git[:repo_id] %>"
19
+ end
20
+ ############### /GOT GIT? #####################################
21
+ <% end %>
22
+
23
+
24
+ # Any pages not listed here will be added
25
+ # to the ebook after the listed pages, in alphabetical order of
26
+ # filename. In this example, the title_page.markdown file goes first,
27
+ # then the foreword.markdown page, then chapters 1 and 2 (in alphanumeric order)
28
+ # and finally the afterword. Any pages not matched will be put after the
29
+ # set of matched pages.
30
+
31
+ pages do
32
+ book [
33
+ # matches title_page.markdown, title_page.textile, or
34
+ # title_page.(any other valid extension). This will be the first
35
+ # scene/chapter/division in the book.
36
+ "title_page",
37
+ "foreword",
38
+
39
+ # filename matches chapter, followed by anything. If you have a page called
40
+ # chapter_summary that comes after, you might want to define the matcher more
41
+ # specifically, for example 'chapter-\d+' (chapter followed by dash followed by any number of numbers).
42
+ #
43
+ "chapter-.*",
44
+ "afterword"
45
+ ]
46
+
47
+ notes [
48
+ # You can set the order that the notes entries appear in below.
49
+ "example89823786",
50
+ "example89723987"
51
+ ]
52
+ end
@@ -0,0 +1,83 @@
1
+ # Add htmlizer classes here. They will be loaded and used in preference over the default htmlizers
2
+ # The default htmlizers are given below as examples.
3
+ #
4
+ #
5
+ # # This htmlizer leaves the input file unaltered
6
+ # EpubForge::Utils::Htmlizer.define do |html|
7
+ # html.format :xhtml
8
+ # html.group :default
9
+ # html.executable "false"
10
+ # html.cmd "cat {{f}}"
11
+ # end
12
+ #
13
+ # # This htmlizer uses the multimarkdown executable.
14
+ # # cmd explains to the htmlizer how to execute as a
15
+ # # shell command:
16
+ # # {{x}} - name of the executable
17
+ # # {{o}} - then come the options
18
+ # # {{f}} - then the name of the file
19
+ # # The output of the executable is captured. The command you
20
+ # # use should output html-tagged text (<h1>...</h1>, <p>...</p>, etc.),
21
+ # # but not a complete html page.
22
+ # EpubForge::Utils::Htmlizer.define do |html|
23
+ # html.format :markdown
24
+ # html.group :default # the default is :user, so user-defined ones don't have to set it
25
+ # html.executable "multimarkdown"
26
+ # html.cmd "{{x}} {{o}} {{f}}"
27
+ # # html.opts "" # the default
28
+ # end
29
+ #
30
+ # EpubForge::Utils::Htmlizer.define do |html|
31
+ # html.format :markdown
32
+ # html.group :default
33
+ # html.executable "pandoc"
34
+ # html.cmd "{{x}} {{o}} {{f}}"
35
+ # html.opts "--from=markdown --to=html"
36
+ # end
37
+ #
38
+ # EpubForge::Utils::Htmlizer.define do |html|
39
+ # html.format :textile
40
+ # html.group :default
41
+ # html.executable "pandoc"
42
+ # html.cmd "{{x}} {{o}} {{f}}"
43
+ # html.opts "--from=textile --to=html"
44
+ # end
45
+ #
46
+ #
47
+ # # Emergency backups
48
+ # EpubForge::Utils::Htmlizer.define do |html|
49
+ # html.format :markdown
50
+ # html.group :fallback
51
+ # html.executable "false"
52
+ # html.cmd "echo \"<pre>\" && cat {{f}} && echo \"</pre>\""
53
+ # end
54
+ #
55
+ # EpubForge::Utils::Htmlizer.define do |html|
56
+ # html.format :textile
57
+ # html.group :fallback
58
+ # html.executable "false"
59
+ # html.cmd "echo \"<pre>\" && cat {{f}} && echo \"</pre>\""
60
+ # end
61
+ #
62
+ # EpubForge::Utils::Htmlizer.define do |html|
63
+ # html.format :txt
64
+ # html.group :fallback
65
+ # html.executable "false"
66
+ # html.cmd "echo \"<pre>\" && cat {{f}} && echo \"</pre>\""
67
+ # end
68
+ #
69
+ # # Would be nice to detect and strip out the outer tags
70
+ # # leaving only the content.
71
+ # EpubForge::Utils::Htmlizer.define do |html|
72
+ # html.format :html
73
+ # html.group :fallback
74
+ # html.executable "false"
75
+ # html.cmd "cat {{f}}"
76
+ # end
77
+ #
78
+ # EpubForge::Utils::Htmlizer.define do |html|
79
+ # html.format :unknown
80
+ # html.group :fallback
81
+ # html.executable "false"
82
+ # html.cmd "echo \"<pre>\" && cat {{f}} && echo \"</pre>\""
83
+ # end
@@ -0,0 +1,6 @@
1
+ # Do not edit this file... I mean, unless you really know what you're doing.
2
+ # If you do, then, please carry on.
3
+ - <%= Time.parse( Time.now.strftime("%Y-%m-%d") ) %>:
4
+ Notes: 0
5
+ Book: 0
6
+
@@ -0,0 +1,24 @@
1
+ # require 'helper'
2
+
3
+ # pulling this feature. May not be worth implementing.
4
+ # class TestDirectoryBuilder < FunWith::Templates::TestCase
5
+ # context "testing template() function which FWT adds to FunWith::Files::DirectoryBuilder" do
6
+ # setup do
7
+ # @templates_dir = FunWith::Templates.root("test", "templates")
8
+ # end
9
+ #
10
+ # should "successfully print off a template" do
11
+ # FunWith::Files::DirectoryBuilder.tmpdir do |b|
12
+ # b.template( @templates_dir.join("00", "a.rb.template") ) do |coll|
13
+ # coll.var(:module, "Cats")
14
+ # coll.var(:class, "Kitten")
15
+ # coll.var(:args, %w(lick paws?))
16
+ # end
17
+ #
18
+ #
19
+ #
20
+ # raise "WORK ON THIS!!!!"
21
+ # end
22
+ # end
23
+ # end
24
+ # end