hydeweb 0.0.8.pre2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/{CHANGELOG → HISTORY.md} +6 -0
  2. data/Rakefile +2 -52
  3. data/bin/hyde +3 -23
  4. data/bin/hyde01 +7 -0
  5. data/data/new_site/README.md +1 -1
  6. data/data/new_site/hyde.conf +9 -6
  7. data/lib/hyde/cli/helpers.rb +40 -0
  8. data/lib/hyde/cli.rb +86 -0
  9. data/lib/hyde/config.rb +37 -0
  10. data/lib/hyde/helpers.rb +6 -47
  11. data/lib/hyde/layout.rb +17 -9
  12. data/lib/hyde/meta.rb +5 -21
  13. data/lib/hyde/page.rb +207 -159
  14. data/lib/hyde/partial.rb +10 -5
  15. data/lib/hyde/project.rb +58 -208
  16. data/lib/hyde/server.rb +57 -0
  17. data/lib/hyde.rb +28 -51
  18. data/test/fixture/extensions/extensions/a/a.rb +1 -0
  19. data/test/fixture/extensions/hyde.conf +8 -0
  20. data/test/fixture/extensions/site/index.haml +1 -0
  21. data/test/fixture/fail_type/control/about/index.html +2 -0
  22. data/test/fixture/fail_type/control/about/us.html +2 -0
  23. data/test/fixture/fail_type/control/index.html +1 -0
  24. data/test/fixture/fail_type/hyde.conf +8 -0
  25. data/test/fixture/fail_type/site/index.haml +4 -0
  26. data/test/fixture/nested_layout/control/index.html +2 -0
  27. data/test/fixture/nested_layout/hyde.conf +8 -0
  28. data/test/fixture/nested_layout/layouts/default.haml +2 -0
  29. data/test/{fixtures/content_for/site/default.html.haml → fixture/nested_layout/layouts/post.haml} +1 -0
  30. data/test/fixture/nested_layout/site/index.haml +4 -0
  31. data/test/fixture/one/control/about/index.css +2 -0
  32. data/test/fixture/one/control/cheers.html +5 -0
  33. data/test/fixture/one/control/css/style.css +2 -0
  34. data/test/fixture/one/control/hello.html +5 -0
  35. data/test/fixture/one/control/hi.html +1 -0
  36. data/test/fixture/one/control/index.html +7 -0
  37. data/test/fixture/one/hyde.conf +9 -0
  38. data/test/fixture/one/layouts/default.haml +4 -0
  39. data/test/fixture/one/partials/menu.haml +3 -0
  40. data/test/fixture/one/site/about/index.scss +1 -0
  41. data/test/fixture/one/site/cheers.html.haml +1 -0
  42. data/test/fixture/one/site/css/style.scss +2 -0
  43. data/test/fixture/one/site/hello.haml +1 -0
  44. data/test/fixture/one/site/hi.html +1 -0
  45. data/test/fixture/one/site/index.haml +7 -0
  46. data/test/fixture/parent/control/about/index.html +2 -0
  47. data/test/fixture/parent/control/about/us.html +2 -0
  48. data/test/fixture/parent/control/index.html +1 -0
  49. data/test/fixture/parent/hyde.conf +8 -0
  50. data/test/fixture/parent/site/about/index.haml +3 -0
  51. data/test/fixture/parent/site/about/us.haml +3 -0
  52. data/test/fixture/parent/site/index.haml +3 -0
  53. data/test/fixture/sort/hyde.conf +8 -0
  54. data/test/fixture/sort/site/about/hardy.haml +4 -0
  55. data/test/fixture/sort/site/about/intrepid.haml +4 -0
  56. data/test/fixture/sort/site/about.haml +3 -0
  57. data/test/fixture/subclass/control/index.html +1 -0
  58. data/test/fixture/subclass/extensions/a/a.rb +12 -0
  59. data/test/fixture/subclass/hyde.conf +8 -0
  60. data/test/fixture/subclass/layouts/default.haml +1 -0
  61. data/test/fixture/subclass/layouts/post.haml +1 -0
  62. data/test/fixture/subclass/site/index.haml +4 -0
  63. data/test/helper.rb +15 -21
  64. data/test/unit/extensions_test.rb +16 -0
  65. data/test/unit/fixture_test.rb +77 -0
  66. data/test/unit/hyde_test.rb +30 -0
  67. metadata +107 -153
  68. data/.yardopts +0 -5
  69. data/LICENSE +0 -20
  70. data/VERSION +0 -1
  71. data/data/new_site/.gitignore +0 -24
  72. data/data/pages/404.html +0 -3
  73. data/hydeweb.gemspec +0 -159
  74. data/lib/hyde/clicommand.rb +0 -60
  75. data/lib/hyde/clicommands.rb +0 -128
  76. data/lib/hyde/ostruct.rb +0 -13
  77. data/lib/hyde/page_factory.rb +0 -90
  78. data/lib/hyde/renderer.rb +0 -133
  79. data/lib/hyde/renderers.rb +0 -100
  80. data/lib/hyde/sinatra/init.rb +0 -64
  81. data/lib/hyde/utils.rb +0 -43
  82. data/lib/hyde_misc/console.rb +0 -4
  83. data/manual/Extending/ExtendingHyde.md +0 -118
  84. data/manual/Hyde.md +0 -63
  85. data/manual/Introduction/Configuration.md +0 -70
  86. data/manual/Introduction/GettingStarted.md +0 -64
  87. data/manual/Introduction/Installation.md +0 -16
  88. data/manual/Introduction/Layouts.md +0 -14
  89. data/manual/Introduction/Metadata.md +0 -94
  90. data/manual/Introduction/Partials.md +0 -73
  91. data/manual/Introduction/TemplateLanguages.md +0 -59
  92. data/manual/Tips/Tips.md +0 -42
  93. data/test/fixtures/content_for/_config.yml +0 -8
  94. data/test/fixtures/content_for/layouts/cf-args.haml +0 -2
  95. data/test/fixtures/content_for/layouts/cf.haml +0 -14
  96. data/test/fixtures/content_for/layouts/default.haml +0 -4
  97. data/test/fixtures/content_for/layouts/shared/test.haml +0 -4
  98. data/test/fixtures/content_for/site/cf-args-default.haml +0 -2
  99. data/test/fixtures/content_for/site/cf-args.haml +0 -5
  100. data/test/fixtures/content_for/site/cf.haml +0 -6
  101. data/test/fixtures/content_for/site/cf2.haml +0 -3
  102. data/test/fixtures/content_for/site/index.html.haml +0 -9
  103. data/test/fixtures/content_for/site/var.html.haml +0 -5
  104. data/test/fixtures/content_for/www_control/cf-args-default.html +0 -1
  105. data/test/fixtures/content_for/www_control/cf-args.html +0 -2
  106. data/test/fixtures/content_for/www_control/cf.html +0 -17
  107. data/test/fixtures/content_for/www_control/cf2.html +0 -19
  108. data/test/fixtures/content_for/www_control/default.html +0 -2
  109. data/test/fixtures/content_for/www_control/index.html +0 -10
  110. data/test/fixtures/content_for/www_control/var.html +0 -2
  111. data/test/fixtures/custom/_config.yml +0 -8
  112. data/test/fixtures/custom/extensions/custom/custom.rb +0 -9
  113. data/test/fixtures/custom/layouts/default.haml +0 -8
  114. data/test/fixtures/custom/layouts/erbtest.erb +0 -2
  115. data/test/fixtures/custom/layouts/shared/sidebar.haml +0 -4
  116. data/test/fixtures/custom/site/about/index.html +0 -1
  117. data/test/fixtures/custom/site/assets/common.css.less +0 -1
  118. data/test/fixtures/custom/site/assets/style.css.less +0 -3
  119. data/test/fixtures/custom/site/foo.html.haml +0 -3
  120. data/test/fixtures/custom/site/index.html.haml +0 -6
  121. data/test/fixtures/custom/site/layout_test.html.haml +0 -6
  122. data/test/fixtures/custom/site/lol.html.erb +0 -7
  123. data/test/fixtures/custom/site/markdown.html.md +0 -8
  124. data/test/fixtures/custom/site/yes.html +0 -2
  125. data/test/fixtures/custom/www_control/about/index.html +0 -1
  126. data/test/fixtures/custom/www_control/assets/common.css +0 -1
  127. data/test/fixtures/custom/www_control/assets/style.css +0 -6
  128. data/test/fixtures/custom/www_control/foo.html +0 -1
  129. data/test/fixtures/custom/www_control/index.html +0 -16
  130. data/test/fixtures/custom/www_control/layout_test.html +0 -16
  131. data/test/fixtures/custom/www_control/lol.html +0 -5
  132. data/test/fixtures/custom/www_control/markdown.html +0 -17
  133. data/test/fixtures/custom/www_control/yes.html +0 -2
  134. data/test/fixtures/default/_config.yml +0 -8
  135. data/test/fixtures/default/extensions/custom/custom.rb +0 -2
  136. data/test/fixtures/default/layouts/default.haml +0 -5
  137. data/test/fixtures/default/site/about/index.html +0 -1
  138. data/test/fixtures/default/site/foo.html.haml +0 -3
  139. data/test/fixtures/default/site/index.html.haml +0 -6
  140. data/test/fixtures/default/site/layout_test.html.haml +0 -6
  141. data/test/fixtures/default/site/yes.html +0 -2
  142. data/test/fixtures/default/www_control/about/index.html +0 -1
  143. data/test/fixtures/default/www_control/foo.html +0 -1
  144. data/test/fixtures/default/www_control/index.html +0 -9
  145. data/test/fixtures/default/www_control/layout_test.html +0 -9
  146. data/test/fixtures/default/www_control/yes.html +0 -2
  147. data/test/test_all_fixtures.rb +0 -51
  148. data/test/test_build.rb +0 -20
  149. data/test/test_hyde.rb +0 -75
  150. data/test/test_page.rb +0 -26
  151. data/test/test_utils.rb +0 -22
data/hydeweb.gemspec DELETED
@@ -1,159 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{hydeweb}
8
- s.version = "0.0.8.pre2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Rico Sta. Cruz", "Sinefunc, Inc."]
12
- s.date = %q{2010-12-30}
13
- s.default_executable = %q{hyde}
14
- s.description = %q{Website preprocessor}
15
- s.email = %q{rico@sinefunc.com}
16
- s.executables = ["hyde"]
17
- s.extra_rdoc_files = [
18
- "LICENSE",
19
- "README.md"
20
- ]
21
- s.files = [
22
- ".yardopts",
23
- "AUTHORS",
24
- "CHANGELOG",
25
- "LICENSE",
26
- "README.md",
27
- "Rakefile",
28
- "VERSION",
29
- "bin/hyde",
30
- "data/new_site/.gitignore",
31
- "data/new_site/README.md",
32
- "data/new_site/hyde.conf",
33
- "data/new_site/layouts/default.haml",
34
- "data/new_site/site/index.html.haml",
35
- "data/pages/404.html",
36
- "hydeweb.gemspec",
37
- "lib/hyde.rb",
38
- "lib/hyde/clicommand.rb",
39
- "lib/hyde/clicommands.rb",
40
- "lib/hyde/helpers.rb",
41
- "lib/hyde/layout.rb",
42
- "lib/hyde/meta.rb",
43
- "lib/hyde/ostruct.rb",
44
- "lib/hyde/page.rb",
45
- "lib/hyde/page_factory.rb",
46
- "lib/hyde/partial.rb",
47
- "lib/hyde/project.rb",
48
- "lib/hyde/renderer.rb",
49
- "lib/hyde/renderers.rb",
50
- "lib/hyde/sinatra/init.rb",
51
- "lib/hyde/utils.rb",
52
- "lib/hyde_misc/console.rb",
53
- "manual/Extending/ExtendingHyde.md",
54
- "manual/Hyde.md",
55
- "manual/Introduction/Configuration.md",
56
- "manual/Introduction/GettingStarted.md",
57
- "manual/Introduction/Installation.md",
58
- "manual/Introduction/Layouts.md",
59
- "manual/Introduction/Metadata.md",
60
- "manual/Introduction/Partials.md",
61
- "manual/Introduction/TemplateLanguages.md",
62
- "manual/Tips/Tips.md",
63
- "test/fixtures/content_for/_config.yml",
64
- "test/fixtures/content_for/layouts/cf-args.haml",
65
- "test/fixtures/content_for/layouts/cf.haml",
66
- "test/fixtures/content_for/layouts/default.haml",
67
- "test/fixtures/content_for/layouts/shared/test.haml",
68
- "test/fixtures/content_for/site/cf-args-default.haml",
69
- "test/fixtures/content_for/site/cf-args.haml",
70
- "test/fixtures/content_for/site/cf.haml",
71
- "test/fixtures/content_for/site/cf2.haml",
72
- "test/fixtures/content_for/site/default.html.haml",
73
- "test/fixtures/content_for/site/index.html.haml",
74
- "test/fixtures/content_for/site/var.html.haml",
75
- "test/fixtures/content_for/www_control/cf-args-default.html",
76
- "test/fixtures/content_for/www_control/cf-args.html",
77
- "test/fixtures/content_for/www_control/cf.html",
78
- "test/fixtures/content_for/www_control/cf2.html",
79
- "test/fixtures/content_for/www_control/default.html",
80
- "test/fixtures/content_for/www_control/index.html",
81
- "test/fixtures/content_for/www_control/var.html",
82
- "test/fixtures/custom/_config.yml",
83
- "test/fixtures/custom/extensions/custom/custom.rb",
84
- "test/fixtures/custom/layouts/default.haml",
85
- "test/fixtures/custom/layouts/erbtest.erb",
86
- "test/fixtures/custom/layouts/shared/sidebar.haml",
87
- "test/fixtures/custom/site/about/index.html",
88
- "test/fixtures/custom/site/assets/common.css.less",
89
- "test/fixtures/custom/site/assets/style.css.less",
90
- "test/fixtures/custom/site/foo.html.haml",
91
- "test/fixtures/custom/site/index.html.haml",
92
- "test/fixtures/custom/site/layout_test.html.haml",
93
- "test/fixtures/custom/site/lol.html.erb",
94
- "test/fixtures/custom/site/markdown.html.md",
95
- "test/fixtures/custom/site/yes.html",
96
- "test/fixtures/custom/www_control/about/index.html",
97
- "test/fixtures/custom/www_control/assets/common.css",
98
- "test/fixtures/custom/www_control/assets/style.css",
99
- "test/fixtures/custom/www_control/foo.html",
100
- "test/fixtures/custom/www_control/index.html",
101
- "test/fixtures/custom/www_control/layout_test.html",
102
- "test/fixtures/custom/www_control/lol.html",
103
- "test/fixtures/custom/www_control/markdown.html",
104
- "test/fixtures/custom/www_control/yes.html",
105
- "test/fixtures/default/_config.yml",
106
- "test/fixtures/default/extensions/custom/custom.rb",
107
- "test/fixtures/default/layouts/default.haml",
108
- "test/fixtures/default/site/about/index.html",
109
- "test/fixtures/default/site/foo.html.haml",
110
- "test/fixtures/default/site/index.html.haml",
111
- "test/fixtures/default/site/layout_test.html.haml",
112
- "test/fixtures/default/site/yes.html",
113
- "test/fixtures/default/www_control/about/index.html",
114
- "test/fixtures/default/www_control/foo.html",
115
- "test/fixtures/default/www_control/index.html",
116
- "test/fixtures/default/www_control/layout_test.html",
117
- "test/fixtures/default/www_control/yes.html",
118
- "test/helper.rb",
119
- "test/test_all_fixtures.rb",
120
- "test/test_build.rb",
121
- "test/test_hyde.rb",
122
- "test/test_page.rb",
123
- "test/test_utils.rb"
124
- ]
125
- s.homepage = %q{http://github.com/sinefunc/hyde}
126
- s.require_paths = ["lib"]
127
- s.rubygems_version = %q{1.3.7}
128
- s.summary = %q{Website preprocessor}
129
- s.test_files = [
130
- "test/fixtures/custom/extensions/custom/custom.rb",
131
- "test/fixtures/default/extensions/custom/custom.rb",
132
- "test/helper.rb",
133
- "test/test_all_fixtures.rb",
134
- "test/test_build.rb",
135
- "test/test_hyde.rb",
136
- "test/test_page.rb",
137
- "test/test_utils.rb"
138
- ]
139
-
140
- if s.respond_to? :specification_version then
141
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
142
- s.specification_version = 3
143
-
144
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
145
- s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
146
- s.add_runtime_dependency(%q<less>, [">= 1.2.21"])
147
- s.add_runtime_dependency(%q<haml>, [">= 2.2.20"])
148
- else
149
- s.add_dependency(%q<sinatra>, [">= 1.0.0"])
150
- s.add_dependency(%q<less>, [">= 1.2.21"])
151
- s.add_dependency(%q<haml>, [">= 2.2.20"])
152
- end
153
- else
154
- s.add_dependency(%q<sinatra>, [">= 1.0.0"])
155
- s.add_dependency(%q<less>, [">= 1.2.21"])
156
- s.add_dependency(%q<haml>, [">= 2.2.20"])
157
- end
158
- end
159
-
@@ -1,60 +0,0 @@
1
- module Hyde
2
- class CLICommand
3
- @@description = nil
4
-
5
- def self.ostream
6
- STDERR
7
- end
8
-
9
- def self.log(str)
10
- ostream << str << "\n"
11
- end
12
-
13
- def self.out(str)
14
- puts str
15
- end
16
-
17
- def self.help
18
- log "Usage: hyde #{self.to_s.downcase.split(':')[-1]}"
19
- log "No help for this command."
20
- end
21
-
22
- def self.lib_path
23
- @@lib_path ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
24
- end
25
-
26
- def self.project
27
- if $project.nil?
28
- files = Hyde::Project.config_filenames.join(", ")
29
- log "Error: Hyde config file not found. (looking for: #{files})"
30
- log "Run this command in a Hyde project directory.\nTo start a new Hyde project, type `hyde create <name>`"
31
- exit
32
- end
33
- $project
34
- end
35
-
36
- def self.hidden?
37
- false
38
- end
39
-
40
- def self.hidden(bool = true)
41
- class_eval %{
42
- def self.hidden?
43
- #{bool.inspect}
44
- end
45
- }
46
- end
47
-
48
- def self.desc(str)
49
- class_eval %{
50
- def self.description
51
- "#{str.gsub('\"','\\\"')}"
52
- end
53
- }
54
- end
55
-
56
- def self.description
57
- ""
58
- end
59
- end
60
- end
@@ -1,128 +0,0 @@
1
- module Hyde
2
- module CLICommands
3
- extend self
4
-
5
- def get_controller(str)
6
- if ['-v', '--version'].include? str
7
- controller = Hyde::CLICommands::Version
8
- elsif ['-h', '-?', '--help'].include? str
9
- controller = Hyde::CLICommands::Help
10
- else
11
- begin
12
- class_name = str.downcase.capitalize.to_sym
13
- controller = Hyde::CLICommands.const_get(class_name)
14
- rescue NameError
15
- STDERR << "Unknown command: #{str}\n"
16
- STDERR << "Type `hyde` for a list of commands.\n"
17
- exit
18
- end
19
- end
20
- controller
21
- end
22
-
23
- class Version < CLICommand
24
- hidden true
25
- def self.run(*a)
26
- out "Hyde version #{Hyde.version}"
27
- end
28
- end
29
-
30
- class Help < CLICommand
31
- hidden true
32
-
33
- def self.run(*a)
34
- if a.size == 0
35
- general_help
36
- exit
37
- end
38
-
39
- controller = CLICommands::get_controller a[0]
40
- controller.help
41
- end
42
-
43
- def self.general_help
44
- log "Usage: hyde <command> [arguments]"
45
- log ""
46
- log "Commands:"
47
-
48
- CLICommands.constants.each do |class_name|
49
- klass = CLICommands.const_get(class_name)
50
- name = class_name.to_s.downcase
51
- unless klass.hidden?
52
- puts " #{name}%s#{klass.description}" % [' ' * (20-name.size)]
53
- end
54
- end
55
-
56
- log ""
57
- log " -h, --help Prints this help screen"
58
- log " -v, --version Show version and exit"
59
- log ""
60
- log "For more info on a command, type `hyde --help <command>`."
61
- end
62
- end
63
-
64
- class Build < CLICommand
65
- desc "Builds the HTML files"
66
- def self.run(*a)
67
- project.build ostream
68
- end
69
- end
70
-
71
- class Start < CLICommand
72
- desc "Starts the local webserver"
73
- def self.run(*a)
74
- project
75
- system "ruby \"%s\"" % [File.join(lib_path, 'hyde', 'sinatra', 'init.rb')]
76
- end
77
-
78
- def self.help
79
- port = project.config.port
80
- log "Usage: hyde start"
81
- log ""
82
- log "This command starts the local webserver. You may then be able to"
83
- log "see your site locally by visiting the URL:"
84
- log ""
85
- log " http://127.0.0.1:#{port}"
86
- log ""
87
- log "You may shut the server down by pressing Ctrl-C."
88
- end
89
- end
90
-
91
- class Console < CLICommand
92
- desc "Starts a console"
93
-
94
- def self.run(*a)
95
- path = File.join(Hyde::LIB_PATH, 'hyde_misc', 'console.rb')
96
- cmd = "irb -r\"#{path}\""
97
- system cmd
98
- end
99
- end
100
-
101
- class Create < CLICommand
102
- desc "Starts a new Hyde project"
103
- def self.run(*a)
104
- unless a.size == 1
105
- log "Usage: hyde create <sitename>"
106
- exit
107
-
108
- else
109
- site_name = a[0]
110
- if File.directory? site_name
111
- log "Directory `#{site_name}` already exists!"
112
- exit
113
- end
114
-
115
- from = File.join(lib_path, '..', 'data', 'new_site')
116
- to = File.expand_path(File.join(Dir.pwd, site_name))
117
-
118
- require 'fileutils'
119
- FileUtils.cp_r from, to
120
-
121
- Dir[File.join(to, '**/*')].each do |file|
122
- log " * %s" % [file.gsub(/^#{Regexp.escape(Dir.pwd)}\/?/, '')]
123
- end
124
- end
125
- end
126
- end
127
- end
128
- end
data/lib/hyde/ostruct.rb DELETED
@@ -1,13 +0,0 @@
1
- require 'ostruct'
2
-
3
- module Hyde
4
- class OStruct < OpenStruct
5
- def merge!(hash)
6
- hash.each_pair { |key, value| self.send "#{key.to_s}=".to_sym, value }
7
- end
8
-
9
- def include?(key)
10
- @table.keys.include? key
11
- end
12
- end
13
- end
@@ -1,90 +0,0 @@
1
- module Hyde
2
- class PageFactory
3
- # Creates a Page with the right class, as defined in the Page's metadata.
4
- #
5
- # Params:
6
- # path - A path, or a filename
7
- #
8
- def self.create(path, project, def_page_class = Page)
9
- # Remove prefix
10
- path.gsub!(project.root(:site), '')
11
- path.gsub!(/^\/+/, '')
12
-
13
- # Try: "file.html" => "file.html", "file" [autoguess], "file/index.html"
14
- ext = File.extname(path)
15
- begin
16
- do_create path, project, def_page_class
17
- rescue NotFound
18
- begin
19
- do_create "#{path.chomp(ext)}", project, def_page_class
20
- rescue NotFound
21
- do_create "#{path}/index.html".squeeze('/'), project, def_page_class
22
- end
23
- end
24
- end
25
-
26
- def self.do_create(path, project, def_page_class = Page)
27
- info = get_page_info(path, project, def_page_class)
28
- page_class = info[:page_class]
29
- page = page_class.new(path, project, info[:renderer], info[:filename])
30
-
31
- # What if it wants to be a different class?
32
- if page.meta.type
33
- begin
34
- klass = Hyde.const_get(page.meta.type.to_sym)
35
- page = klass.new(path, project, info[:renderer], info[:filename])
36
- rescue NameError #pass
37
- end
38
- else
39
- page
40
- end
41
- end
42
-
43
- protected
44
-
45
- # Returns the renderer, filename, page class
46
- def self.get_page_info(path, project, page_class)
47
- renderer = nil
48
- filename = page_class.get_filename(path, project)
49
-
50
- if File.directory? filename
51
- raise NotFound, "`#{path}` is a directory, not a file"
52
-
53
- elsif File.exists? filename
54
- ext = File.extname(filename)[1..-1]
55
- renderer = Hyde::Renderer.get(ext)
56
-
57
- else
58
- # Look for the file
59
- matches = Dir["#{filename}.*"]
60
- if matches.empty?
61
- raise NotFound, "Can't find `#{path}{,.*}` -- #{filename}"
62
- end
63
-
64
- # Check for a matching renderer
65
- exts = []
66
- matches.each do |match|
67
- begin
68
- ext = File.extname(match)[1..-1].capitalize.to_sym
69
- exts << File.extname(match)
70
- r_class = Hyde::Renderers.const_get(ext) # .get(ext, nil)
71
- renderer ||= r_class
72
- filename = match
73
- rescue NoMethodError
74
- # pass
75
- rescue NameError # Renderer not found
76
- # pass
77
- end
78
- end
79
-
80
- raise NotFound, "No matching (#{exts.join(", ")}) renderers found for `#{path}`" \
81
- if renderer.nil?
82
- end
83
-
84
- { :renderer => renderer,
85
- :filename => filename,
86
- :page_class => page_class
87
- }
88
- end
89
- end
90
- end
data/lib/hyde/renderer.rb DELETED
@@ -1,133 +0,0 @@
1
- require "ostruct"
2
-
3
- module Hyde
4
- module Renderer
5
- extend self
6
-
7
- def get(extname, default=Hyde::Renderer::Passthru)
8
- klass = extname.to_s.capitalize.to_sym
9
-
10
- begin
11
- Hyde::Renderers.const_get(klass)
12
- rescue NameError
13
- default
14
- end
15
- end
16
-
17
- class Base
18
- include Hyde::Utils
19
-
20
- # Reference to {Page}
21
- attr_reader :page
22
-
23
- # The filename of the file to be parsed
24
- attr_reader :filename
25
-
26
- def initialize(page, filename)
27
- @page = page
28
- @filename = filename
29
- end
30
-
31
- def render(data, &block)
32
- scope = build_scope(page, data, &block)
33
- evaluate scope, data, &block
34
- end
35
-
36
- def markup
37
- File.open(filename) { |f| @markup = f.read } unless @markup
38
- @markup
39
- end
40
-
41
- def layoutable?(*a) self.class.layoutable?(*a); end
42
- def default_ext(*a) self.class.default_ext(*a); end
43
-
44
- def self.layoutable?() false; end
45
- def self.default_ext() ''; end
46
-
47
- protected
48
- def require_lib(lib, gem=lib)
49
- begin
50
- require lib
51
- rescue LoadError
52
- class_name = self.class.to_s.downcase
53
- ext = /[^:]*$/.match(class_name)
54
- raise NoGemError.new("To use .#{ext} files, type: `gem install #{gem}`")
55
- end
56
- end
57
-
58
- def build_scope(page, data, &block)
59
- # Page is the scope
60
- scope = page.get_binding &block
61
- scope_object = eval("self", scope)
62
-
63
- # Inherit local vars
64
- data_object = data.inject({}) { |a, i| a[i[0].to_s] = i[1]; a }
65
- scope_object.send(:instance_variable_set, '@_locals', data_object)
66
- f_set_locals = data_object.keys.map { |k| "#{k} = @_locals[#{k.inspect}];" }.join("\n")
67
- eval(f_set_locals, scope)
68
-
69
- scope_object.instance_eval do
70
- get_helpers.each { |helper_class| extend helper_class }
71
- end
72
-
73
- scope
74
- end
75
-
76
- # Override me
77
- def evaluate(scope, data, &block)
78
- ""
79
- end
80
- end
81
-
82
- # Any filetype that is split with the -- separator
83
- class Parsable < Base
84
- def self.default_ext
85
- '.html'
86
- end
87
-
88
- def initialize(page, filename)
89
- super page, filename
90
-
91
- # Parse out the file's metadata and markup contents
92
- parts = get_file_parts filename, :max_parts => 2
93
- if parts.length == 1
94
- # If it doesn't come with a header, assume the whole file is the data
95
- @markup = parts[0]
96
- else
97
- @markup = parts[1]
98
- page.meta.merge! YAML::load("--- " + parts[0])
99
- end
100
- end
101
-
102
- def markup
103
- @markup
104
- end
105
-
106
- protected
107
- def get_file_parts(filename, *args)
108
- options = { :max_parts => -1 }
109
- args.each_pair { |k, v| options[k] = v } if args.is_a? Hash
110
-
111
- data = [""]
112
- i = 0 # Current part number
113
- File.open(filename, "r").each_line do |line|
114
- if ((line.strip == "--") and
115
- ((i <= options[:max_parts]) or (options[:max_parts] == -1)))
116
- data[i+=1] = ""
117
- else
118
- data[i] << line
119
- end
120
- end
121
- data
122
- end
123
- end
124
-
125
- class Passthru < Base
126
- def render(data = 0, &block)
127
- output = ''
128
- File.open(@page.filename, "r") { |f| output = f.read }
129
- output
130
- end
131
- end
132
- end
133
- end
@@ -1,100 +0,0 @@
1
- module Hyde
2
- module Renderers
3
- class Haml < Renderer::Parsable
4
- def self.layoutable?() true; end
5
- def self.default_ext() '.html'; end
6
-
7
- def evaluate(scope, data={}, &block)
8
- require 'haml'
9
- begin
10
- @engine = ::Haml::Engine.new(markup, engine_options)
11
- @engine.render scope, data, &block
12
- rescue ::Haml::SyntaxError => e
13
- raise Hyde::RenderError.new(e.message, :line => e.line)
14
- end
15
- end
16
-
17
- protected
18
- def engine_options
19
- { :escape_html => true }
20
- end
21
- end
22
-
23
- class Erb < Renderer::Parsable
24
- def self.layoutable?() true; end
25
- def self.default_ext() '.html'; end
26
-
27
- def evaluate(scope, data={}, &block)
28
- require_lib 'erb'
29
- @engine = ::ERB.new markup
30
- eval @engine.src, scope
31
- end
32
- end
33
-
34
- class Sass < Haml
35
- def self.layoutable?() false; end
36
- def self.default_ext() '.css'; end
37
-
38
- def evaluate(scope, data={}, &block)
39
- require 'sass'
40
- begin
41
- @engine = ::Sass::Engine.new(markup, engine_options)
42
- @engine.render
43
- rescue ::Sass::SyntaxError => e
44
- raise Hyde::RenderError.new(e.message, :line => e.line)
45
- end
46
- end
47
-
48
- protected
49
- def engine_options
50
- { :syntax => :sass, :load_paths => [File.dirname(@filename)], :cache => false }
51
- end
52
- end
53
-
54
- class Scss < Sass
55
- protected
56
- def engine_options
57
- super.merge :syntax => :scss
58
- end
59
- end
60
-
61
- class Less < Renderer::Base
62
- def self.default_ext
63
- '.css'
64
- end
65
-
66
- def evaluate(scope, data={}, &block)
67
- require_lib 'less'
68
- begin
69
- @engine = ::Less::Engine.new(File.open(filename))
70
- @engine.to_css
71
- rescue ::Less::SyntaxError => e
72
- matches = /^on line ([0-9]+): (.*)$/.match(e.message)
73
- line = matches[1]
74
- message = matches[2]
75
- raise Hyde::RenderError.new(message, :line => line)
76
- end
77
- end
78
- end
79
-
80
- class Md < Renderer::Parsable
81
- def self.layoutable?() true; end
82
- def self.default_ext() '.html'; end
83
-
84
- def evaluate(s, d={}, &block)
85
- require_lib 'maruku'
86
- Maruku.new(markup).to_html
87
- end
88
- end
89
-
90
- class Textile < Renderer::Parsable
91
- def self.layoutable?() true; end
92
- def self.default_ext() '.html'; end
93
-
94
- def evaluate(s, d={}, &block)
95
- require_lib 'redcloth', 'RedCloth'
96
- RedCloth.new(markup).to_html
97
- end
98
- end
99
- end
100
- end