smartgen 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +14 -0
- data/Gemfile.lock +2 -2
- data/README.md +7 -0
- data/lib/smartgen/configuration.rb +1 -49
- data/lib/smartgen/engines.rb +1 -0
- data/lib/smartgen/engines/base.rb +3 -3
- data/lib/smartgen/engines/erb.rb +15 -0
- data/lib/smartgen/engines/markdown.rb +1 -1
- data/lib/smartgen/engines/textile.rb +1 -1
- data/lib/smartgen/generator.rb +29 -17
- data/lib/smartgen/markup_file.rb +6 -2
- data/lib/smartgen/object_hash.rb +15 -5
- data/lib/smartgen/rake_task.rb +21 -5
- data/lib/smartgen/renderers/erb.rb +1 -4
- data/lib/smartgen/resource.rb +1 -9
- data/lib/smartgen/version.rb +1 -1
- data/spec/fixtures/expectations/common/another_index.html +13 -0
- data/spec/fixtures/expectations/common/index.html +8 -0
- data/spec/fixtures/expectations/common/other_index.html +13 -0
- data/spec/fixtures/expectations/erb/index.html +15 -0
- data/spec/fixtures/expectations/erb/with_layout/index.html +19 -0
- data/spec/fixtures/expectations/indexer/index_with_indexer.html +16 -0
- data/spec/fixtures/expectations/indexer/index_with_indexer_and_numbered_index.html +16 -0
- data/spec/fixtures/expectations/with_layout/index.html +12 -0
- data/spec/fixtures/expectations/with_layout/index_with_metadata.html +43 -0
- data/spec/fixtures/expectations/with_layout/index_with_specific_metadata.html +44 -0
- data/spec/fixtures/src/assets/images/image.gif +0 -0
- data/spec/fixtures/src/assets/javascripts/somelib.js +2 -0
- data/spec/fixtures/src/assets/stylesheets/style.css +2 -0
- data/spec/fixtures/src/common/another_index.md +12 -0
- data/spec/fixtures/src/common/index.textile +10 -0
- data/spec/fixtures/src/common/other_index.markdown +12 -0
- data/spec/fixtures/src/common/somefile +10 -0
- data/spec/fixtures/src/erb/index.html.erb +7 -0
- data/spec/fixtures/src/erb/with_layout/index.html.erb +7 -0
- data/spec/fixtures/src/erb/with_layout/layout.html.erb +5 -0
- data/spec/fixtures/src/indexer/index_with_indexer.textile +26 -0
- data/spec/fixtures/src/indexer/index_with_indexer_and_numbered_index.textile +26 -0
- data/spec/fixtures/src/layout.html.erb +5 -0
- data/spec/fixtures/src/layout_with_metadata.html.erb +22 -0
- data/spec/fixtures/src/layout_with_specific_metadata.html.erb +23 -0
- data/spec/fixtures/src/metadata.yml +43 -0
- data/spec/fixtures/src/with_layout/index.textile +10 -0
- data/spec/fixtures/src/with_layout/index_with_specific_metadata.textile +10 -0
- data/spec/lib/smartgen/configuration_spec.rb +5 -0
- data/spec/lib/smartgen/engines/base_spec.rb +73 -0
- data/spec/lib/smartgen/engines/erb_spec.rb +37 -0
- data/spec/lib/smartgen/engines/markdown_spec.rb +23 -0
- data/spec/lib/smartgen/engines/textile_spec.rb +19 -0
- data/spec/lib/smartgen/generator_spec.rb +272 -0
- data/spec/lib/smartgen/indexer_spec.rb +122 -0
- data/spec/lib/smartgen/markup_file_spec.rb +168 -0
- data/spec/lib/smartgen/object_hash_spec.rb +91 -0
- data/spec/lib/smartgen/renderers/erb_spec.rb +32 -0
- data/spec/lib/smartgen/resource_spec.rb +73 -0
- data/spec/lib/smartgen/watcher_spec.rb +71 -0
- data/spec/lib/smartgen_spec.rb +18 -0
- data/spec/sandbox/.gitkeep +0 -0
- data/spec/spec_helper.rb +37 -0
- metadata +99 -13
data/ChangeLog.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
0.5.0
|
2
|
+
-----
|
3
|
+
|
4
|
+
* Added ERB engine
|
5
|
+
* Added a sample Thorfile and fixed thor generator description so that it can be properly used.
|
6
|
+
* Configuration options are passed directly to generators to avoid duplicate options definitions
|
7
|
+
* Allowing one to pass a different resource name for rake task
|
8
|
+
* Metadata will be passed as an ObjectHash to renderers and engines
|
9
|
+
|
10
|
+
0.4.0
|
11
|
+
-----
|
12
|
+
|
13
|
+
* Passing metadata to engines and their preprocessors.
|
14
|
+
|
1
15
|
0.3.0
|
2
16
|
-----
|
3
17
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smartgen (0.
|
4
|
+
smartgen (0.5.0)
|
5
5
|
RedCloth (= 4.2.3)
|
6
6
|
activesupport (>= 2.3.5)
|
7
7
|
bluecloth (>= 2.0.9)
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
remote: http://rubygems.org/
|
15
15
|
specs:
|
16
16
|
RedCloth (4.2.3)
|
17
|
-
activesupport (3.
|
17
|
+
activesupport (2.3.5)
|
18
18
|
archive-tar-minitar (0.5.2)
|
19
19
|
bluecloth (2.0.10)
|
20
20
|
columnize (0.3.2)
|
data/README.md
CHANGED
@@ -161,6 +161,13 @@ Then you can call both `my_doc` and `watch_my_doc`:
|
|
161
161
|
rake my_doc # generates files right away
|
162
162
|
rake watch_my_doc # generates files and watch for changes
|
163
163
|
|
164
|
+
## Related Gems
|
165
|
+
|
166
|
+
* [Smartgen SyntaxHighlighter](http://github.com/smartgen/smartgen_syntaxhighlighter) -- Adds support to use Alex Gorbatchev's Syntax Highlighter plugin with smartgen
|
167
|
+
* [Smartgen ERB](http://github.com/smartgen/smartgen_erb) -- A ERB preprocessor for smartgen engines
|
168
|
+
|
169
|
+
There are some
|
170
|
+
|
164
171
|
## Contributors
|
165
172
|
|
166
173
|
* [Vicente Mundim](http://github.com/vicentemundim) _(author)_
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Smartgen
|
2
|
-
|
3
2
|
# Holds configurations for each smartgen resource.
|
4
|
-
class Configuration
|
3
|
+
class Configuration < ObjectHash
|
5
4
|
|
6
5
|
# An array with all the source files that should be generated.
|
7
6
|
#
|
@@ -18,52 +17,5 @@ module Smartgen
|
|
18
17
|
# default:
|
19
18
|
# nil
|
20
19
|
attr_accessor :output_folder
|
21
|
-
|
22
|
-
# An optional layout file to be used when rendering each page.
|
23
|
-
#
|
24
|
-
# default:
|
25
|
-
# nil
|
26
|
-
attr_accessor :layout
|
27
|
-
|
28
|
-
# An array of dirs to be copied to output folder.
|
29
|
-
#
|
30
|
-
# It will copy the contents of each directory to the output folder,
|
31
|
-
# preserving the directory itself. So, if output folder is '/public/doc',
|
32
|
-
# then 'doc/stylesheets' will be copied to 'public/docs/stylesheets'.
|
33
|
-
#
|
34
|
-
# default:
|
35
|
-
# []
|
36
|
-
attr_accessor :assets
|
37
|
-
|
38
|
-
# A YAML metadata file used to specify metadata used in all pages, or even
|
39
|
-
# specific page metadata.
|
40
|
-
#
|
41
|
-
# default:
|
42
|
-
# nil
|
43
|
-
attr_accessor :metadata_file
|
44
|
-
|
45
|
-
# Whether indexer should be used or not.
|
46
|
-
#
|
47
|
-
# default:
|
48
|
-
# false
|
49
|
-
attr_accessor :use_indexer
|
50
|
-
|
51
|
-
# Whether indexer should add numbered indexes on header tags.
|
52
|
-
#
|
53
|
-
# Only makes sense if #use_indexer is true
|
54
|
-
#
|
55
|
-
# default:
|
56
|
-
# false
|
57
|
-
attr_accessor :numbered_index
|
58
|
-
|
59
|
-
def initialize
|
60
|
-
@src_files = []
|
61
|
-
@output_folder = nil
|
62
|
-
@layout = nil
|
63
|
-
@assets = []
|
64
|
-
@metadata_file = nil
|
65
|
-
@use_indexer = false
|
66
|
-
@numbered_index = false
|
67
|
-
end
|
68
20
|
end
|
69
21
|
end
|
data/lib/smartgen/engines.rb
CHANGED
@@ -14,8 +14,8 @@ module Smartgen
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Process a file, calling each pre processor if any.
|
17
|
-
def process(body, metadata=
|
18
|
-
parse(pre_process(body, metadata))
|
17
|
+
def process(body, metadata=Smartgen::ObjectHash.new)
|
18
|
+
parse(pre_process(body, metadata), metadata)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Returns true if the given extension is supported by this engine.
|
@@ -39,7 +39,7 @@ module Smartgen
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def parse(body)
|
42
|
+
def parse(body, metadata)
|
43
43
|
body
|
44
44
|
end
|
45
45
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Smartgen
|
2
|
+
module Engine
|
3
|
+
# Processes erb files, supporting '.erb' extension.
|
4
|
+
class ERB < Base
|
5
|
+
protected
|
6
|
+
def parse(body, metadata)
|
7
|
+
::ERB.new(body).result(binding)
|
8
|
+
end
|
9
|
+
|
10
|
+
def extensions
|
11
|
+
@extensions ||= ['.erb']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/smartgen/generator.rb
CHANGED
@@ -5,26 +5,28 @@ module Smartgen
|
|
5
5
|
class Generator < Thor::Group
|
6
6
|
include Thor::Actions
|
7
7
|
|
8
|
-
desc "
|
9
|
-
argument :src_files, :type => :array
|
8
|
+
desc "Process given markup files, generating HTML, optionally using a layout and copying assets."
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
argument :src_files, :type => :array,
|
11
|
+
:desc => "An array with all the source files that should be generated."
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
argument :output_folder, :type => :string,
|
14
|
+
:desc => "The output folder, where all generated files will be located."
|
16
15
|
|
17
|
-
|
18
|
-
|
16
|
+
class_option :layout, :type => :string,
|
17
|
+
:desc => "An optional layout file to be used when rendering each page."
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
class_option :assets, :type => :array, :default => [],
|
20
|
+
:desc => "An array of dirs to be copied to output folder."
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
class_option :metadata_file, :type => :string,
|
23
|
+
:desc => "A YAML metadata file used to specify metadata used in all pages, or even specific page metadata."
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
class_option :use_indexer, :type => :boolean, :default => false,
|
26
|
+
:desc => "Whether indexer should be used or not."
|
27
|
+
|
28
|
+
class_option :numbered_index, :type => :boolean, :default => false,
|
29
|
+
:desc => "Whether indexer should add numbered indexes on header tags."
|
28
30
|
|
29
31
|
def create_output_folder
|
30
32
|
destination_root = output_folder
|
@@ -85,9 +87,9 @@ module Smartgen
|
|
85
87
|
|
86
88
|
def load_metadata
|
87
89
|
if options["metadata_file"]
|
88
|
-
YAML.load(File.read(options["metadata_file"]))
|
90
|
+
Smartgen::ObjectHash.new(YAML.load(File.read(options["metadata_file"])))
|
89
91
|
else
|
90
|
-
|
92
|
+
Smartgen::ObjectHash.new
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
@@ -106,7 +108,7 @@ module Smartgen
|
|
106
108
|
end
|
107
109
|
|
108
110
|
def markup_files
|
109
|
-
|
111
|
+
supported_src_files.map do |markup_filename|
|
110
112
|
MarkupFile.new markup_filename, markup_file_options
|
111
113
|
end
|
112
114
|
end
|
@@ -119,10 +121,20 @@ module Smartgen
|
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
124
|
+
def supported_src_files
|
125
|
+
Dir[*src_files].select do |path|
|
126
|
+
supported?(File.extname(path)) && !layout?(path)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
122
130
|
def supported?(extension)
|
123
131
|
MarkupFile.engines.one? { |engine| engine.supported?(extension) }
|
124
132
|
end
|
125
133
|
|
134
|
+
def layout?(file)
|
135
|
+
File.expand_path(options[:layout]) == File.expand_path(file) if has_layout?
|
136
|
+
end
|
137
|
+
|
126
138
|
def output_folder_path(path)
|
127
139
|
File.join(output_folder, path)
|
128
140
|
end
|
data/lib/smartgen/markup_file.rb
CHANGED
@@ -40,7 +40,7 @@ module Smartgen
|
|
40
40
|
def initialize(path, options={})
|
41
41
|
@path = path
|
42
42
|
@extension = File.extname(path)
|
43
|
-
@filename =
|
43
|
+
@filename = filename_for(path)
|
44
44
|
@engine = engine_for(@extension) || self.class.engines.first
|
45
45
|
|
46
46
|
@contents = engine.process(raw_contents, options[:metadata])
|
@@ -64,7 +64,7 @@ module Smartgen
|
|
64
64
|
# first ones are the ones with higher priority.
|
65
65
|
def engines
|
66
66
|
if @engines.blank?
|
67
|
-
@engines = [Smartgen::Engine::Textile.new, Smartgen::Engine::Markdown.new]
|
67
|
+
@engines = [Smartgen::Engine::Textile.new, Smartgen::Engine::Markdown.new, Smartgen::Engine::ERB.new]
|
68
68
|
end
|
69
69
|
|
70
70
|
@engines
|
@@ -87,5 +87,9 @@ module Smartgen
|
|
87
87
|
|
88
88
|
nil
|
89
89
|
end
|
90
|
+
|
91
|
+
def filename_for(path)
|
92
|
+
File.basename(File.basename(path, @extension), '.html')
|
93
|
+
end
|
90
94
|
end
|
91
95
|
end
|
data/lib/smartgen/object_hash.rb
CHANGED
@@ -11,21 +11,31 @@ module Smartgen
|
|
11
11
|
def dup
|
12
12
|
Smartgen::ObjectHash.new(self)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def respond_to?(method)
|
16
|
-
has_key?(method)
|
16
|
+
has_key?(method) || (setter?(method) && has_key?(method.to_s.chop)) || super
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
"ObjectHash(#{super})"
|
17
21
|
end
|
18
|
-
|
22
|
+
|
19
23
|
protected
|
20
24
|
def method_missing(name, *args)
|
21
25
|
if has_key?(name)
|
22
26
|
self[name]
|
27
|
+
elsif setter?(name)
|
28
|
+
self[name.to_s.chop] = args.first
|
23
29
|
else
|
24
|
-
puts "warning: key #{name} not found on #{inspect}"
|
30
|
+
$stderr.puts "warning: key #{name} not found on #{inspect}"
|
25
31
|
Smartgen::ObjectHash.new
|
26
32
|
end
|
27
33
|
end
|
28
|
-
|
34
|
+
|
35
|
+
def setter?(method)
|
36
|
+
method.to_s.end_with?('=')
|
37
|
+
end
|
38
|
+
|
29
39
|
def convert_value(value)
|
30
40
|
case value
|
31
41
|
when Hash
|
data/lib/smartgen/rake_task.rb
CHANGED
@@ -20,15 +20,31 @@ module Smartgen
|
|
20
20
|
#
|
21
21
|
# It yields a Configuration, in fact it calls Resource#configure, so you
|
22
22
|
# can use any of the configurations here.
|
23
|
+
#
|
24
|
+
# You may also use an existing configuration, while still having a different
|
25
|
+
# task name:
|
26
|
+
# Smartgen[:my_config] do |config|
|
27
|
+
# config.layout = 'layout.html.erb'
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# Smartgen::RakeTask.new :watcher, :my_config do |config|
|
31
|
+
# config.src_files = ['doc/**/*']
|
32
|
+
# config.output_folder = 'public/doc'
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# This will use Smartgen[:generate_doc] config, but you will call it with:
|
36
|
+
#
|
37
|
+
# rake watcher
|
23
38
|
class RakeTask < ::Rake::TaskLib
|
24
|
-
def initialize(
|
25
|
-
|
39
|
+
def initialize(resource_or_task_name=nil, resource_name=nil, &block)
|
40
|
+
task_name = resource_or_task_name || :smartgen
|
41
|
+
resource_name = resource_name || task_name
|
26
42
|
|
27
|
-
Smartgen[
|
43
|
+
Smartgen[resource_name].configure(&block)
|
28
44
|
|
29
45
|
desc("Generate smartgen files") unless ::Rake.application.last_comment
|
30
|
-
task
|
31
|
-
Smartgen[
|
46
|
+
task task_name do
|
47
|
+
Smartgen[resource_name].generate!
|
32
48
|
end
|
33
49
|
end
|
34
50
|
end
|
@@ -6,10 +6,7 @@ module Smartgen
|
|
6
6
|
#
|
7
7
|
# It exposes +markup_file+ variable and its +metadata+ to the ERB layout.
|
8
8
|
def render(layout, markup_file, metadata={})
|
9
|
-
|
10
|
-
|
11
|
-
template = ::ERB.new(layout)
|
12
|
-
template.result(binding)
|
9
|
+
::ERB.new(layout).result(binding)
|
13
10
|
end
|
14
11
|
end
|
15
12
|
end
|
data/lib/smartgen/resource.rb
CHANGED
@@ -31,19 +31,11 @@ module Smartgen
|
|
31
31
|
|
32
32
|
private
|
33
33
|
def generator
|
34
|
-
Smartgen::Generator.new(arguments,
|
34
|
+
Smartgen::Generator.new(arguments, config)
|
35
35
|
end
|
36
36
|
|
37
37
|
def arguments
|
38
38
|
[config.src_files, config.output_folder]
|
39
39
|
end
|
40
|
-
|
41
|
-
def options
|
42
|
-
{
|
43
|
-
:metadata_file => config.metadata_file,
|
44
|
-
:layout => config.layout,
|
45
|
-
:assets => config.assets
|
46
|
-
}
|
47
|
-
end
|
48
40
|
end
|
49
41
|
end
|
data/lib/smartgen/version.rb
CHANGED