neapolitan 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,26 @@
1
- Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION) # becuase Ruby 1.8~ gets in the way
2
-
3
1
  module Neapolitan
4
2
 
5
- DIRECTORY = File.dirname(__FILE__)
6
-
7
- def self.gemfile
8
- @gemfile ||= (
3
+ def self.package
4
+ @package ||= (
9
5
  require 'yaml'
10
- YAML.load(File.new(DIRECTORY + '/gemfile'))
6
+ YAML.load(File.new(File.dirname(__FILE__) + '/package'))
11
7
  )
12
8
  end
13
9
 
14
10
  def self.profile
15
11
  @profile ||= (
16
12
  require 'yaml'
17
- YAML.load(File.new(DIRECTORY + '/profile'))
13
+ YAML.load(File.new(File.dirname(__FILE__) + '/profile'))
18
14
  )
19
15
  end
20
16
 
21
17
  def self.const_missing(name)
22
18
  key = name.to_s.downcase
23
- gemfile[key] || profile[key] || super(name)
19
+ package[key] || profile[key] || super(name)
24
20
  end
25
21
 
26
22
  end
27
23
 
24
+ # Becuase Ruby 1.8~ gets in the way
25
+ Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION)
26
+
@@ -0,0 +1,12 @@
1
+ name : neapolitan
2
+ date : 2010-11-09
3
+ version : 0.3.0
4
+
5
+ requires:
6
+ - malt
7
+ - syckle (build)
8
+ - qed (test)
9
+ - rdiscount (optional, test)
10
+ - redcloth (optional, test)
11
+ - rdoc 2.5+ (optional, test, document)
12
+
@@ -1,27 +1,26 @@
1
- Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION) # becuase Ruby 1.8~ gets in the way
2
-
3
1
  module Neapolitan
4
2
 
5
- DIRECTORY = File.dirname(__FILE__)
6
-
7
- def self.gemfile
8
- @gemfile ||= (
3
+ def self.package
4
+ @package ||= (
9
5
  require 'yaml'
10
- YAML.load(File.new(DIRECTORY + '/gemfile'))
6
+ YAML.load(File.new(File.dirname(__FILE__) + '/package'))
11
7
  )
12
8
  end
13
9
 
14
10
  def self.profile
15
11
  @profile ||= (
16
12
  require 'yaml'
17
- YAML.load(File.new(DIRECTORY + '/profile'))
13
+ YAML.load(File.new(File.dirname(__FILE__) + '/profile'))
18
14
  )
19
15
  end
20
16
 
21
17
  def self.const_missing(name)
22
18
  key = name.to_s.downcase
23
- gemfile[key] || profile[key] || super(name)
19
+ package[key] || profile[key] || super(name)
24
20
  end
25
21
 
26
22
  end
27
23
 
24
+ # Becuase Ruby 1.8~ gets in the way
25
+ Object.__send__(:remove_const, :VERSION) if Object.const_defined?(:VERSION)
26
+
@@ -0,0 +1,12 @@
1
+ name : neapolitan
2
+ date : 2010-11-09
3
+ version : 0.3.0
4
+
5
+ requires:
6
+ - malt
7
+ - syckle (build)
8
+ - qed (test)
9
+ - rdiscount (optional, test)
10
+ - redcloth (optional, test)
11
+ - rdoc 2.5+ (optional, test, document)
12
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neapolitan
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Sawyer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-14 00:00:00 -04:00
18
+ date: 2010-11-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: rdiscount
36
+ name: syckle
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :development
48
48
  version_requirements: *id002
49
49
  - !ruby/object:Gem::Dependency
50
- name: redcloth
50
+ name: qed
51
51
  prerelease: false
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -61,7 +61,7 @@ dependencies:
61
61
  type: :development
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: haml
64
+ name: rdiscount
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
@@ -75,24 +75,9 @@ dependencies:
75
75
  type: :development
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency
78
- name: rdoc
78
+ name: redcloth
79
79
  prerelease: false
80
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 9
86
- segments:
87
- - 2
88
- - 5
89
- version: "2.5"
90
- type: :development
91
- version_requirements: *id005
92
- - !ruby/object:Gem::Dependency
93
- name: syckle
94
- prerelease: false
95
- requirement: &id006 !ruby/object:Gem::Requirement
96
81
  none: false
97
82
  requirements:
98
83
  - - ">="
@@ -102,21 +87,22 @@ dependencies:
102
87
  - 0
103
88
  version: "0"
104
89
  type: :development
105
- version_requirements: *id006
90
+ version_requirements: *id005
106
91
  - !ruby/object:Gem::Dependency
107
- name: qed
92
+ name: rdoc
108
93
  prerelease: false
109
- requirement: &id007 !ruby/object:Gem::Requirement
94
+ requirement: &id006 !ruby/object:Gem::Requirement
110
95
  none: false
111
96
  requirements:
112
97
  - - ">="
113
98
  - !ruby/object:Gem::Version
114
- hash: 3
99
+ hash: 9
115
100
  segments:
116
- - 0
117
- version: "0"
101
+ - 2
102
+ - 5
103
+ version: "2.5"
118
104
  type: :development
119
- version_requirements: *id007
105
+ version_requirements: *id006
120
106
  description: Neapolitan is a meta-templating engine. Like a candy store it allows you to pick and choose from a variety of rendering formats in the construction of a single document. Selections include eruby, textile, markdown and many others.
121
107
  email: rubyworks-mailinglist@googlegroups.com
122
108
  executables:
@@ -127,23 +113,13 @@ extra_rdoc_files:
127
113
  - README.rdoc
128
114
  files:
129
115
  - bin/neapolitan
130
- - lib/neapolitan/command.rb
131
- - lib/neapolitan/config.rb
132
- - lib/neapolitan/document.rb
133
- - lib/neapolitan/factory.rb
134
116
  - lib/neapolitan/meta/data.rb
135
- - lib/neapolitan/meta/gemfile
117
+ - lib/neapolitan/meta/package
136
118
  - lib/neapolitan/meta/profile
137
- - lib/neapolitan/part.rb
138
- - lib/neapolitan/template.rb
139
119
  - lib/neapolitan.rb
140
120
  - meta/data.rb
141
- - meta/gemfile
121
+ - meta/package
142
122
  - meta/profile
143
- - qed/fixtures/example.html
144
- - qed/fixtures/example.npt
145
- - qed/fixtures/example.yaml
146
- - qed/overview.rdoc
147
123
  - HISTORY.rdoc
148
124
  - LICENSE
149
125
  - README.rdoc
@@ -1,84 +0,0 @@
1
- require 'neapolitan'
2
-
3
- module Neapolitan
4
-
5
- # Command line interface.
6
-
7
- class Command
8
-
9
- def self.main(*argv)
10
- new(*argv).call
11
- end
12
-
13
- def initialize(*argv)
14
- @output = nil
15
- @noharm = false
16
- @trace = false
17
- @data_file = nil
18
-
19
- parser.parse!(argv)
20
-
21
- @files = argv
22
- end
23
-
24
- def parser
25
- OptionParser.new do |opt|
26
- opt.banner = "neapolitan [file1 file2 ...]"
27
-
28
- opt.on("--output", "-o [PATH]", "save output to specified directory") do |path|
29
- @output = path
30
- end
31
-
32
- opt.on("--source", "-s [FILE]", "source data file") do |file|
33
- @data_file = file
34
- end
35
-
36
- opt.on("--trace", "show extra operational information") do
37
- $TRACE = true
38
- end
39
-
40
- opt.on("--dryrun", "-n", "don't actually write to disk") do
41
- $DRYRUN = true
42
- end
43
-
44
- opt.on("--debug", "run in debug mode") do
45
- $DEBUG = true
46
- $VERBOSE = true
47
- end
48
-
49
- opt.on_tail("--help", "display this help message") do
50
- puts opt
51
- exit
52
- end
53
- end
54
- end
55
-
56
- #
57
- def call
58
- begin
59
- @files.each do |file|
60
- doc = Document.new(file, data)
61
- if @output
62
- #doc.save
63
- else
64
- puts doc
65
- end
66
- end
67
- rescue => e
68
- $DEBUG ? raise(e) : puts(e.message)
69
- end
70
- end
71
-
72
- #
73
- def data
74
- if @data_file
75
- YAML.load(File.new(@data_file))
76
- else
77
- {} #@source ||= YAML.load(STDIN.read)
78
- end
79
- end
80
-
81
- end
82
-
83
- end
84
-
@@ -1,30 +0,0 @@
1
- require 'ostruct'
2
-
3
- module Neapolitan
4
-
5
- # Configuration
6
- class Config
7
-
8
- #
9
- DEFAULTS = {
10
- :stencil => 'rhtml',
11
- #:format => 'html',
12
- :pagelayout => 'page',
13
- :postlayout => 'post',
14
- :maxchars => 500,
15
- }
16
-
17
- attr :defaults
18
-
19
- def initialize
20
- if File.exist?('.config/defaults')
21
- custom_defaults = YAML.load(File.new('.config/defaults'))
22
- else
23
- custom_defaults = {}
24
- end
25
- @defaults = OpenStruct.new(DEFAULTS.merge(custom_defaults))
26
- end
27
- end
28
-
29
- end
30
-
@@ -1,76 +0,0 @@
1
- require 'neapolitan/template'
2
-
3
- module Neapolitan
4
-
5
- # = Neapolitan Document
6
- #
7
- # The Document class encapsulates a file which
8
- # can be then be rendered via a Neapolitan::Template.
9
- class Document
10
-
11
- # File path.
12
- attr :file
13
-
14
- #
15
- attr :template
16
-
17
- # New Document object.
18
- #
19
- # file - path to neapolitan formatted file
20
- # options - configuration passed on to the Template class
21
- #
22
- # Returns a new Document object.
23
- def initialize(file, options={})
24
- case file
25
- when File
26
- @file = file.name
27
- @text = file.read
28
- @file.close
29
- when String
30
- @file = file
31
- @text = File.read(file)
32
- end
33
-
34
- @template = Template.new(@text, options)
35
- end
36
-
37
- #
38
- def inspect
39
- "<#{self.class}: @file='#{file}'>"
40
- end
41
-
42
- # Name of file less extname.
43
- #def name
44
- # @name ||= file.chomp(File.extname(file))
45
- #end
46
-
47
- #
48
- def render(data={}, &block)
49
- @template.render(data, &block)
50
- end
51
-
52
- # TODO: how to handle extension?
53
- def save(*path_and_data, &block)
54
- data = Hash===path_and_data.last ? path_and_data.pop : {}
55
- path = path_and_data
56
-
57
- rendering = render(data, &block)
58
- extension = rendering.header['extension'] || '.html'
59
-
60
- path = Dir.pwd unless path
61
- if File.directory?(path)
62
- file = File.join(path, file.chomp(File.extname(file)) + extension)
63
- else
64
- file = path
65
- end
66
-
67
- if $DRYRUN
68
- $stderr << "[DRYRUN] write #{fname}"
69
- else
70
- File.open(fname, 'w'){ |f| f << rendering.to_s }
71
- end
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,209 +0,0 @@
1
- #require 'tilt'
2
- require 'malt'
3
-
4
- module Neapolitan
5
-
6
- # Controls rendering to a variety of back-end templating
7
- # and markup systems.
8
- #
9
- module Factory
10
- extend self
11
-
12
- #
13
- def render(format, text, source, &yld)
14
- #table = {}
15
- #scope = Object.new
16
-
17
- case source
18
- when Hash
19
- db = source
20
- when Binding
21
- db = source
22
- else # object scope
23
- db = source
24
- end
25
-
26
- case format
27
- when /^coderay/
28
- coderay(text, format)
29
- when /^syntax/
30
- syntax(text, format)
31
- else
32
- doc = Malt.text(text, :format=>format.to_sym)
33
- doc.render(db, &yld)
34
- #if engine = Tilt[format]
35
- # engine.new{text}.render(scope, table, &yld)
36
- #else
37
- # text
38
- #end
39
- end
40
- end
41
-
42
- #
43
- #def redcloth(input)
44
- # RedCloth.new(input).to_html
45
- #end
46
-
47
- #def bluecloth(input)
48
- # BlueCloth.new(input).to_html
49
- #end
50
-
51
- #def rdiscount(input)
52
- # RDiscount.new(input).to_html
53
- #end
54
-
55
- def rdoc(input)
56
- markup = RDoc::Markup::ToHtml.new
57
- markup.convert(input)
58
- end
59
-
60
- #def haml(input)
61
- # Haml::Engine.new(input).render
62
- #end
63
-
64
- def coderay(input, format)
65
- require 'coderay'
66
- format = format.split('.')[1] || :ruby #:plaintext
67
- tokens = CodeRay.scan(input, format.to_sym) #:ruby
68
- tokens.div()
69
- end
70
-
71
- #
72
- def syntax(input, format)
73
- require 'syntax/convertors/html'
74
- format = format.split('.')[1] || 'ruby' #:plaintext
75
- lines = true
76
- conv = Syntax::Convertors::HTML.for_syntax(format)
77
- conv.convert(input,lines)
78
- end
79
-
80
- # Stencil Rendering
81
- # -----------------
82
-
83
- #
84
- #def render_stencil(stencil, text, attributes)
85
- # case stencil
86
- # when 'rhtml'
87
- # erb(text, attributes)
88
- # when 'liquid'
89
- # liquid(text, attributes)
90
- # else
91
- # text
92
- # end
93
- #end
94
-
95
- #
96
- #def erb(input, attributes)
97
- # template = ERB.new(input)
98
- # context = TemplateContext.new(attributes)
99
- # result = template.result(context.__binding__)
100
- # result
101
- #end
102
-
103
- #def liquid(input, attributes)
104
- # template = Liquid::Template.parse(input)
105
- # result = template.render(attributes, :filters => [TemplateFilters])
106
- # result
107
- #end
108
-
109
- =begin
110
- # Require Dependencies
111
- # --------------------
112
-
113
- # TODO: Load engines only if used.
114
-
115
- begin ; require 'rubygems' ; rescue LoadError ; end
116
- begin ; require 'erb' ; rescue LoadError ; end
117
- begin ; require 'redcloth' ; rescue LoadError ; end
118
- begin ; require 'bluecloth' ; rescue LoadError ; end
119
- begin ; require 'rdiscount' ; rescue LoadError ; end
120
-
121
- begin
122
- require 'liquid'
123
- #Liquid::Template.register_filter(TemplateFilters)
124
- rescue LoadError
125
- end
126
-
127
- begin
128
- require 'haml'
129
- #Haml::Template.options[:format] = :html5
130
- rescue LoadError
131
- end
132
- =end
133
-
134
- begin
135
- require 'rdoc/markup'
136
- require 'rdoc/markup/to_html'
137
- rescue LoadError
138
- end
139
-
140
- end
141
-
142
- =begin
143
- # = Clean Rendering Context
144
- #
145
- # The Factory Context is is used by ERB.
146
-
147
- class Context
148
- #include TemplateFilters
149
-
150
- instance_methods(true).each{ |m| private m unless m =~ /^__/ }
151
-
152
- def initialize(attributes={})
153
- @attributes = attributes
154
- end
155
-
156
- def __binding__
157
- binding
158
- end
159
-
160
- def to_h
161
- @attributes
162
- end
163
-
164
- def method_missing(s, *a)
165
- s = s.to_s
166
- @attributes.key?(s) ? @attributes[s] : super
167
- end
168
- end
169
- =end
170
-
171
- #
172
- #
173
- #
174
-
175
- #module TemplateFilters
176
-
177
- # NOTE: HTML truncate did not work well.
178
-
179
- # # HTML comment regular expression
180
- # REM_RE = %r{<\!--(.*?)-->}
181
- #
182
- # # HTML tag regular expression
183
- # TAG_RE = %r{</?\w+((\s+\w+(\s*=\s*(?:"(.|\n)*?"|'(.|\n)*?'|[^'">\s]+))?)+\s*|\s*)/?>} #'
184
- #
185
- # #
186
- # def truncate_html(html, limit)
187
- # return html unless limit
188
- #
189
- # mask = html.gsub(REM_RE){ |m| "\0" * m.size }
190
- # mask = mask.gsub(TAG_RE){ |m| "\0" * m.size }
191
- #
192
- # i, x = 0, 0
193
- #
194
- # while i < mask.size && x < limit
195
- # x += 1 if mask[i] != "\0"
196
- # i += 1
197
- # end
198
- #
199
- # while x > 0 && mask[x,1] == "\0"
200
- # x -= 1
201
- # end
202
- #
203
- # return html[0..x]
204
- # end
205
-
206
- #end
207
-
208
- end
209
-