merb-pagination 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -0
- data/History.txt +4 -0
- data/License.txt +22 -0
- data/Manifest.txt +25 -0
- data/README.txt +34 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +72 -0
- data/config/requirements.rb +15 -0
- data/lib/merb-pagination.rb +14 -0
- data/lib/merb-pagination/hash.rb +8 -0
- data/lib/merb-pagination/pagination_helper.rb +130 -0
- data/lib/merb-pagination/version.rb +9 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +84 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_helper.rb +2 -0
- data/test/test_merb-pagination.rb +11 -0
- data/website/index.txt +106 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +46 -0
- metadata +139 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�]Y�)�bE��5�ǢE��� ��y��ƽ�88S�A2no#������,��q������&X!q�Ӫe��W�N��J����
|
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2008 Lori Holden
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/merb-pagination.rb
|
9
|
+
lib/merb-pagination/hash.rb
|
10
|
+
lib/merb-pagination/pagination_helper.rb
|
11
|
+
lib/merb-pagination/version.rb
|
12
|
+
script/console
|
13
|
+
script/destroy
|
14
|
+
script/generate
|
15
|
+
script/txt2html
|
16
|
+
setup.rb
|
17
|
+
tasks/deployment.rake
|
18
|
+
tasks/environment.rake
|
19
|
+
tasks/website.rake
|
20
|
+
test/test_helper.rb
|
21
|
+
test/test_merb-pagination.rb
|
22
|
+
website/index.txt
|
23
|
+
website/javascripts/rounded_corners_lite.inc.js
|
24
|
+
website/stylesheets/screen.css
|
25
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= merb_pagination
|
2
|
+
|
3
|
+
* http://merb-pagination.rubyforge.org
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A pagination helper for merb. Useful with dm-is-paginated
|
8
|
+
|
9
|
+
See the website for more details.
|
10
|
+
|
11
|
+
== LICENSE:
|
12
|
+
|
13
|
+
(The MIT License)
|
14
|
+
|
15
|
+
Copyright (c) 2008 Lori Holden
|
16
|
+
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
18
|
+
a copy of this software and associated documentation files (the
|
19
|
+
'Software'), to deal in the Software without restriction, including
|
20
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
21
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
22
|
+
permit persons to whom the Software is furnished to do so, subject to
|
23
|
+
the following conditions:
|
24
|
+
|
25
|
+
The above copyright notice and this permission notice shall be
|
26
|
+
included in all copies or substantial portions of the Software.
|
27
|
+
|
28
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
29
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
30
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
31
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
32
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
33
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
34
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'merb-pagination/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Lori Holden'
|
4
|
+
EMAIL = "email+gem@loriholden.com"
|
5
|
+
DESCRIPTION = "A pagination helper for merb"
|
6
|
+
GEM_NAME = 'merb-pagination'
|
7
|
+
RUBYFORGE_PROJECT = 'merb-pagination'
|
8
|
+
HOMEPATH = "http://merb-pagination.rubyforge.org/"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
['merb-core', '>= 0.9.4'],
|
12
|
+
['builder', '>= 2.0.0']
|
13
|
+
]
|
14
|
+
|
15
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
16
|
+
@config = nil
|
17
|
+
RUBYFORGE_USERNAME = "lholden"
|
18
|
+
def rubyforge_username
|
19
|
+
unless @config
|
20
|
+
begin
|
21
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
22
|
+
rescue
|
23
|
+
puts <<-EOS
|
24
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
25
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
26
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
27
|
+
EOS
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
REV = nil
|
36
|
+
VERS = MerbPagination::VERSION::STRING + (REV ? ".#{REV}" : "")
|
37
|
+
RDOC_OPTS = ['--quiet', '--title', 'merb_pagination documentation',
|
38
|
+
"--opname", "index.html",
|
39
|
+
"--line-numbers",
|
40
|
+
"--main", "README",
|
41
|
+
"--inline-source"]
|
42
|
+
|
43
|
+
class Hoe
|
44
|
+
def extra_deps
|
45
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
46
|
+
@extra_deps
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Generate all the Rake tasks
|
51
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
52
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
53
|
+
p.developer(AUTHOR, EMAIL)
|
54
|
+
p.description = DESCRIPTION
|
55
|
+
p.summary = DESCRIPTION
|
56
|
+
p.url = HOMEPATH
|
57
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
58
|
+
p.test_globs = ["test/**/test_*.rb"]
|
59
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
60
|
+
|
61
|
+
# == Optional
|
62
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
63
|
+
p.extra_deps = EXTRA_DEPENDENCIES
|
64
|
+
|
65
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
66
|
+
end
|
67
|
+
|
68
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
69
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
70
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
71
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
72
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Needed to import merb and other gems
|
2
|
+
require 'rubygems'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Add all external dependencies for the plugin here
|
6
|
+
gem 'merb-core', '>=0.9.4'
|
7
|
+
require 'merb-core'
|
8
|
+
|
9
|
+
# Require plugin-files
|
10
|
+
dir = Pathname(__FILE__).dirname.expand_path / 'merb-pagination'
|
11
|
+
require dir / "hash"
|
12
|
+
require dir / 'pagination_helper'
|
13
|
+
|
14
|
+
Merb::Controller.send(:include, Merb::PaginationHelper)
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'builder'
|
2
|
+
module Merb
|
3
|
+
module PaginationHelper
|
4
|
+
# Given a page count and the current page, we generate a set of pagination
|
5
|
+
# links.
|
6
|
+
#
|
7
|
+
# * We use an inner and outer window into a list of links. For a set of
|
8
|
+
# 20 pages with the current page being 10:
|
9
|
+
# outer_window:
|
10
|
+
# 1 2 ..... 19 20
|
11
|
+
# inner_window
|
12
|
+
# 5 6 7 8 9 10 11 12 13 14
|
13
|
+
#
|
14
|
+
# This is totally adjustable, or can be turned off by giving the
|
15
|
+
# :inner_window setting a value of nil.
|
16
|
+
#
|
17
|
+
# * Options
|
18
|
+
# :class => <em>css_class</em::
|
19
|
+
# The CSS class to be given to the paginator div.
|
20
|
+
# Defaults to 'paginated'
|
21
|
+
# :prev_label => <em>text_for_previous_link</em>::
|
22
|
+
# Defaults to '« Previous '
|
23
|
+
# :next_labe => <em>text_for_next_link</em>::
|
24
|
+
# Defaults to ' Next »'
|
25
|
+
# :left_cut_label => <em>text_for_cut</em>::
|
26
|
+
# Used when the page numbers need to be cut off to prevent the set of
|
27
|
+
# pagination links from being too long.
|
28
|
+
# Defaults to '←'
|
29
|
+
# :right_cut_label => <em>text_for_cut</em>::
|
30
|
+
# Same as :left_cut_label but for the right side of numbers.
|
31
|
+
# Defaults to '→'
|
32
|
+
# :outer_window => <em>number_of_pages</em>::
|
33
|
+
# Sets the number of pages to include in the outer 'window'
|
34
|
+
# Defaults to 2
|
35
|
+
# :inner_window => <em>number_of_pages</em>::
|
36
|
+
# Sets the number of pags to include in the inner 'window'
|
37
|
+
# Defaults to 10
|
38
|
+
# :default_css => <em>use_paginator_provided_css</em>
|
39
|
+
# Use the default CSS provided by the paginator. If you want to do
|
40
|
+
# your own custom styling of the paginator from scratch, set this to
|
41
|
+
# false.
|
42
|
+
# Defaults to true
|
43
|
+
# :page_param => <em>name_of_page_paramiter</em>
|
44
|
+
# Sets the name of the paramiter the paginator uses to return what
|
45
|
+
# page is being requested.
|
46
|
+
# Defaults to 'page'
|
47
|
+
# :url => <em>url_for_links</em>
|
48
|
+
# Provides the base url to use in the page navigation links.
|
49
|
+
# Defaults to ''
|
50
|
+
def paginate(current_page, page_count, options = {})
|
51
|
+
options.reverse_merge!({
|
52
|
+
:class => 'paginated',
|
53
|
+
:prev_label => '« Previous ',
|
54
|
+
:next_label => ' Next »',
|
55
|
+
:left_cut_label => '←',
|
56
|
+
:right_cut_label => '→',
|
57
|
+
:outer_window => 2,
|
58
|
+
:inner_window => 10,
|
59
|
+
:default_css => true,
|
60
|
+
:page_param => 'page',
|
61
|
+
:url => ''
|
62
|
+
})
|
63
|
+
url = options.delete :url
|
64
|
+
url << (url.include?('?') ? '&' : '?') << options[:page_param]
|
65
|
+
|
66
|
+
pages = {
|
67
|
+
:all => (1 .. page_count).to_a,
|
68
|
+
:left => [],
|
69
|
+
:center => [],
|
70
|
+
:right => []
|
71
|
+
}
|
72
|
+
|
73
|
+
# Only worry about using our 'windows' if the page count is less then
|
74
|
+
# our windows combined.
|
75
|
+
if options[:inner_window].nil? or ((options[:outer_window] *2) + options[:inner_window] + 2) >= page_count
|
76
|
+
pages[:center] = pages[:all]
|
77
|
+
else
|
78
|
+
pages[:left] = pages[:all][0, options[:outer_window]]
|
79
|
+
pages[:right] = pages[:all][page_count - options[:outer_window], options[:outer_window]]
|
80
|
+
pages[:center] = case current_page
|
81
|
+
# allow the inner 'window' to shift to right when close to the left edge
|
82
|
+
# Ex: 1 2 [3] 4 5 6 7 8 9 ... 20
|
83
|
+
when -infinity .. (options[:inner_window] / 2) +3
|
84
|
+
pages[:all][options[:outer_window], options[:inner_window]] +
|
85
|
+
[options[:right_cut_label]]
|
86
|
+
# allow the inner 'window' to shift left when close to the right edge
|
87
|
+
# Ex: 1 2 ... 12 13 14 15 16 [17] 18 19 20
|
88
|
+
when (page_count - (options[:inner_window] / 2.0).ceil) -1 .. infinity
|
89
|
+
[options[:left_cut_label]] +
|
90
|
+
pages[:all][page_count - options[:inner_window] - options[:outer_window], options[:inner_window]]
|
91
|
+
# Display the unshifed window
|
92
|
+
# ex: 1 2 ... 5 6 7 [8] 9 10 11 ... 19 20
|
93
|
+
else
|
94
|
+
[options[:left_cut_label]] +
|
95
|
+
pages[:all][current_page - (options[:inner_window] / 2) -1, options[:inner_window]] +
|
96
|
+
[options[:right_cut_label]]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Builder::XmlMarkup.new.div(:class => options[:class]) do |b|
|
101
|
+
b.style {|s| s << %Q{
|
102
|
+
div.#{options[:class]} ul, div.#{options[:class]} ul li {
|
103
|
+
display: inline;
|
104
|
+
padding: 2px;
|
105
|
+
}
|
106
|
+
} } if options[:default_css]
|
107
|
+
b << (current_page <= 1 ? options[:prev_label] : %Q{<a href="#{url}=#{current_page -1}">#{options[:prev_label]}</a>})
|
108
|
+
|
109
|
+
b.ul do
|
110
|
+
[pages[:left], pages[:center], pages[:right]].each do |p|
|
111
|
+
p.each do |page_number|
|
112
|
+
case page_number
|
113
|
+
when String
|
114
|
+
b.li(:class=>'more_marker') {|li| li << page_number}
|
115
|
+
when current_page
|
116
|
+
b.li(page_number, :class=>'current_page')
|
117
|
+
else
|
118
|
+
b.li { b.a(page_number, :href=>"#{url}=#{page_number}") }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
b << (current_page >= page_count ? options[:next_label] : %Q{<a href="#{url}=#{current_page +1}">#{options[:next_label]}</a>})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
private
|
128
|
+
def infinity; 1.0/0; end
|
129
|
+
end
|
130
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/merb_pagination.rb'}"
|
9
|
+
puts "Loading merb_pagination gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
GEM_NAME = 'merb-pagination' # what ppl will type to install your gem
|
4
|
+
RUBYFORGE_PROJECT = 'merb-pagination'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
begin
|
8
|
+
require 'newgem'
|
9
|
+
require 'rubyforge'
|
10
|
+
rescue LoadError
|
11
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
12
|
+
puts "Install: gem install newgem\n\n"
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
require 'redcloth'
|
16
|
+
require 'syntax/convertors/html'
|
17
|
+
require 'erb'
|
18
|
+
require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
|
19
|
+
|
20
|
+
version = MerbPagination::VERSION::STRING
|
21
|
+
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
22
|
+
|
23
|
+
def rubyforge_project_id
|
24
|
+
rf = RubyForge.new
|
25
|
+
rf.configure
|
26
|
+
rf.autoconfigautoconfig["group_ids"][RUBYFORGE_PROJECT]
|
27
|
+
end
|
28
|
+
|
29
|
+
class Fixnum
|
30
|
+
def ordinal
|
31
|
+
# teens
|
32
|
+
return 'th' if (10..19).include?(self % 100)
|
33
|
+
# others
|
34
|
+
case self % 10
|
35
|
+
when 1: return 'st'
|
36
|
+
when 2: return 'nd'
|
37
|
+
when 3: return 'rd'
|
38
|
+
else return 'th'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Time
|
44
|
+
def pretty
|
45
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def convert_syntax(syntax, source)
|
50
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
51
|
+
end
|
52
|
+
|
53
|
+
if ARGV.length >= 1
|
54
|
+
src, template = ARGV
|
55
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
56
|
+
else
|
57
|
+
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
58
|
+
exit!
|
59
|
+
end
|
60
|
+
|
61
|
+
template = ERB.new(File.open(template).read)
|
62
|
+
|
63
|
+
title = nil
|
64
|
+
body = nil
|
65
|
+
File.open(src) do |fsrc|
|
66
|
+
title_text = fsrc.readline
|
67
|
+
body_text_template = fsrc.read
|
68
|
+
body_text = ERB.new(body_text_template).result(binding)
|
69
|
+
syntax_items = []
|
70
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
71
|
+
ident = syntax_items.length
|
72
|
+
element, syntax, source = $1, $2, $3
|
73
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
74
|
+
"syntax-temp-#{ident}"
|
75
|
+
}
|
76
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
77
|
+
body = RedCloth.new(body_text).to_html
|
78
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
79
|
+
end
|
80
|
+
stat = File.stat(src)
|
81
|
+
created = stat.ctime
|
82
|
+
modified = stat.mtime
|
83
|
+
|
84
|
+
$stdout << template.result(binding)
|