porthole 0.99.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +415 -0
  3. data/Rakefile +89 -0
  4. data/bin/porthole +94 -0
  5. data/lib/porthole.rb +304 -0
  6. data/lib/porthole/context.rb +142 -0
  7. data/lib/porthole/generator.rb +195 -0
  8. data/lib/porthole/parser.rb +263 -0
  9. data/lib/porthole/settings.rb +226 -0
  10. data/lib/porthole/sinatra.rb +205 -0
  11. data/lib/porthole/template.rb +58 -0
  12. data/lib/porthole/version.rb +3 -0
  13. data/lib/rack/bug/panels/mustache_panel.rb +81 -0
  14. data/lib/rack/bug/panels/mustache_panel/mustache_extension.rb +27 -0
  15. data/lib/rack/bug/panels/mustache_panel/view.mustache +46 -0
  16. data/man/porthole.1 +165 -0
  17. data/man/porthole.1.html +213 -0
  18. data/man/porthole.1.ron +127 -0
  19. data/man/porthole.5 +539 -0
  20. data/man/porthole.5.html +422 -0
  21. data/man/porthole.5.ron +324 -0
  22. data/test/autoloading_test.rb +56 -0
  23. data/test/fixtures/comments.porthole +1 -0
  24. data/test/fixtures/comments.rb +14 -0
  25. data/test/fixtures/complex_view.porthole +17 -0
  26. data/test/fixtures/complex_view.rb +34 -0
  27. data/test/fixtures/crazy_recursive.porthole +9 -0
  28. data/test/fixtures/crazy_recursive.rb +31 -0
  29. data/test/fixtures/delimiters.porthole +8 -0
  30. data/test/fixtures/delimiters.rb +23 -0
  31. data/test/fixtures/dot_notation.porthole +10 -0
  32. data/test/fixtures/dot_notation.rb +25 -0
  33. data/test/fixtures/double_section.porthole +7 -0
  34. data/test/fixtures/double_section.rb +14 -0
  35. data/test/fixtures/escaped.porthole +1 -0
  36. data/test/fixtures/escaped.rb +14 -0
  37. data/test/fixtures/inner_partial.porthole +1 -0
  38. data/test/fixtures/inner_partial.txt +1 -0
  39. data/test/fixtures/inverted_section.porthole +7 -0
  40. data/test/fixtures/inverted_section.rb +14 -0
  41. data/test/fixtures/lambda.porthole +7 -0
  42. data/test/fixtures/lambda.rb +31 -0
  43. data/test/fixtures/method_missing.rb +19 -0
  44. data/test/fixtures/namespaced.porthole +1 -0
  45. data/test/fixtures/namespaced.rb +25 -0
  46. data/test/fixtures/nested_objects.porthole +17 -0
  47. data/test/fixtures/nested_objects.rb +35 -0
  48. data/test/fixtures/node.porthole +8 -0
  49. data/test/fixtures/partial_with_module.porthole +4 -0
  50. data/test/fixtures/partial_with_module.rb +37 -0
  51. data/test/fixtures/passenger.conf +5 -0
  52. data/test/fixtures/passenger.rb +27 -0
  53. data/test/fixtures/recursive.porthole +4 -0
  54. data/test/fixtures/recursive.rb +14 -0
  55. data/test/fixtures/simple.porthole +5 -0
  56. data/test/fixtures/simple.rb +26 -0
  57. data/test/fixtures/template_partial.porthole +2 -0
  58. data/test/fixtures/template_partial.rb +18 -0
  59. data/test/fixtures/template_partial.txt +4 -0
  60. data/test/fixtures/unescaped.porthole +1 -0
  61. data/test/fixtures/unescaped.rb +14 -0
  62. data/test/fixtures/utf8.porthole +3 -0
  63. data/test/fixtures/utf8_partial.porthole +1 -0
  64. data/test/helper.rb +7 -0
  65. data/test/parser_test.rb +78 -0
  66. data/test/partial_test.rb +168 -0
  67. data/test/porthole_test.rb +677 -0
  68. data/test/spec_test.rb +68 -0
  69. data/test/template_test.rb +20 -0
  70. metadata +127 -0
@@ -0,0 +1,68 @@
1
+ require 'porthole'
2
+ require 'tmpdir'
3
+ require 'yaml'
4
+ require 'test/unit'
5
+
6
+ # Automatically process !code types into Proc objects
7
+ YAML::add_builtin_type('code') { |_, val| eval(val['ruby']) }
8
+
9
+ # A simple base class for Porthole specs.
10
+ # Creates a partials directory, then points a (dynamic) subclass of Porthole at
11
+ # that directory before each test; the partials directory is destroyed after
12
+ # each test is run.
13
+ class PortholeSpec < Test::Unit::TestCase
14
+ def setup
15
+ @partials = File.join(File.dirname(__FILE__), 'partials')
16
+ Dir.mkdir(@partials)
17
+
18
+ @Porthole = Class.new(Porthole)
19
+ @Porthole.template_path = @partials
20
+ end
21
+
22
+ def teardown
23
+ Dir[File.join(@partials, '*')].each { |file| File.delete(file) }
24
+ Dir.rmdir(@partials)
25
+ end
26
+
27
+ # Extracts the partials from the test, and dumps them into the partials
28
+ # directory for inclusion.
29
+ def setup_partials(test)
30
+ (test['partials'] || {}).each do |name, content|
31
+ File.open(File.join(@partials, "#{name}.porthole"), 'w') do |f|
32
+ f.print(content)
33
+ end
34
+ end
35
+ end
36
+
37
+ # Asserts equality between the rendered template and the expected value,
38
+ # printing additional context data on failure.
39
+ def assert_porthole_spec(test)
40
+ actual = @Porthole.render(test['template'], test['data'])
41
+
42
+ assert_equal test['expected'], actual, "" <<
43
+ "#{ test['desc'] }\n" <<
44
+ "Data: #{ test['data'].inspect }\n" <<
45
+ "Template: #{ test['template'].inspect }\n" <<
46
+ "Partials: #{ (test['partials'] || {}).inspect }\n"
47
+ end
48
+
49
+ def test_noop; assert(true); end
50
+ end
51
+
52
+ spec_files = File.join(File.dirname(__FILE__), '..', 'ext', 'spec', 'specs', '*.yml')
53
+ Dir[spec_files].each do |file|
54
+ spec = YAML.load_file(file)
55
+
56
+ klass_name = "Test" + File.basename(file, ".yml").sub(/~/, '').capitalize
57
+ instance_eval "class ::#{klass_name} < PortholeSpec; end"
58
+ test_suite = Kernel.const_get(klass_name)
59
+
60
+ test_suite.class_eval do
61
+ spec['tests'].each do |test|
62
+ define_method :"test - #{test['name']}" do
63
+ setup_partials(test)
64
+ assert_porthole_spec(test)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'helper'
3
+
4
+ class TemplateTest < Test::Unit::TestCase
5
+ def test_compile
6
+ assert_equal %("foo"), Porthole::Template.new("foo").compile
7
+ end
8
+
9
+ def test_compile_with_source
10
+ assert_equal %("bar"), Porthole::Template.new("foo").compile("bar")
11
+ end
12
+
13
+ def test_token
14
+ assert_equal [:multi, [:static, "foo"]], Porthole::Template.new("foo").tokens
15
+ end
16
+
17
+ def test_token_with_source
18
+ assert_equal [:multi, [:static, "bar"]], Porthole::Template.new("foo").tokens("bar")
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: porthole
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.99.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Gonyea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Porthole is a ripoff of Mustache. It replaces the use of {{ }} with
15
+ %% %%, because god hates me.
16
+
17
+
18
+ I removed the Mustache authors from the list of authors, as I don''t want to associate
19
+ their names
20
+
21
+ with this project. You can find the *real* list of authors by viewing the Ruby Gem
22
+ "mustache" or
23
+
24
+ by going to: http://github.com/defunkt/mustache
25
+
26
+ '
27
+ email: me@sgonyea.com
28
+ executables:
29
+ - porthole
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - Rakefile
35
+ - LICENSE
36
+ - lib/porthole/context.rb
37
+ - lib/porthole/generator.rb
38
+ - lib/porthole/parser.rb
39
+ - lib/porthole/settings.rb
40
+ - lib/porthole/sinatra.rb
41
+ - lib/porthole/template.rb
42
+ - lib/porthole/version.rb
43
+ - lib/porthole.rb
44
+ - lib/rack/bug/panels/mustache_panel/mustache_extension.rb
45
+ - lib/rack/bug/panels/mustache_panel/view.mustache
46
+ - lib/rack/bug/panels/mustache_panel.rb
47
+ - bin/porthole
48
+ - man/porthole.1
49
+ - man/porthole.1.html
50
+ - man/porthole.1.ron
51
+ - man/porthole.5
52
+ - man/porthole.5.html
53
+ - man/porthole.5.ron
54
+ - test/autoloading_test.rb
55
+ - test/fixtures/comments.porthole
56
+ - test/fixtures/comments.rb
57
+ - test/fixtures/complex_view.porthole
58
+ - test/fixtures/complex_view.rb
59
+ - test/fixtures/crazy_recursive.porthole
60
+ - test/fixtures/crazy_recursive.rb
61
+ - test/fixtures/delimiters.porthole
62
+ - test/fixtures/delimiters.rb
63
+ - test/fixtures/dot_notation.porthole
64
+ - test/fixtures/dot_notation.rb
65
+ - test/fixtures/double_section.porthole
66
+ - test/fixtures/double_section.rb
67
+ - test/fixtures/escaped.porthole
68
+ - test/fixtures/escaped.rb
69
+ - test/fixtures/inner_partial.porthole
70
+ - test/fixtures/inner_partial.txt
71
+ - test/fixtures/inverted_section.porthole
72
+ - test/fixtures/inverted_section.rb
73
+ - test/fixtures/lambda.porthole
74
+ - test/fixtures/lambda.rb
75
+ - test/fixtures/method_missing.rb
76
+ - test/fixtures/namespaced.porthole
77
+ - test/fixtures/namespaced.rb
78
+ - test/fixtures/nested_objects.porthole
79
+ - test/fixtures/nested_objects.rb
80
+ - test/fixtures/node.porthole
81
+ - test/fixtures/partial_with_module.porthole
82
+ - test/fixtures/partial_with_module.rb
83
+ - test/fixtures/passenger.conf
84
+ - test/fixtures/passenger.rb
85
+ - test/fixtures/recursive.porthole
86
+ - test/fixtures/recursive.rb
87
+ - test/fixtures/simple.porthole
88
+ - test/fixtures/simple.rb
89
+ - test/fixtures/template_partial.porthole
90
+ - test/fixtures/template_partial.rb
91
+ - test/fixtures/template_partial.txt
92
+ - test/fixtures/unescaped.porthole
93
+ - test/fixtures/unescaped.rb
94
+ - test/fixtures/utf8.porthole
95
+ - test/fixtures/utf8_partial.porthole
96
+ - test/helper.rb
97
+ - test/parser_test.rb
98
+ - test/partial_test.rb
99
+ - test/porthole_test.rb
100
+ - test/spec_test.rb
101
+ - test/template_test.rb
102
+ homepage: http://github.com/sgonyea/porthole
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.15
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Porthole is a framework-agnostic way to render logic-free views.
126
+ test_files: []
127
+ has_rdoc: