deplot 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +27 -4
  2. data/bin/deplot +41 -10
  3. data/deplot.gemspec +1 -1
  4. metadata +1 -1
data/README.md CHANGED
@@ -89,6 +89,20 @@ end
89
89
 
90
90
  `collect_in` concatenates all the rendered files and writes them to a single file. Like `output_to`, it can be called with a block (the `apply` example makes use of this feature).
91
91
 
92
+ #### render (documents only)
93
+
94
+ `render` expects a block. This block is called when rendering (the only argument is the array of sources) and *replaces* the default renderer. You can use this method to define your own rendering process. The following code parses each source as YAML and renders a template using the YAML data:
95
+
96
+ ```
97
+ render do |sources|
98
+ sources.each do |source|
99
+ metadata = YAML::load(source[:content])
100
+ post_renderer = Tilt.new("assets/post.erb")
101
+ source[:content] = post_renderer.render(nil, metadata)
102
+ end
103
+ end
104
+ ```
105
+
92
106
  #### filter
93
107
 
94
108
  The `filter` command is available for both media and document renderers and is used to filter out files from the specified sources. It can be used in two ways:
@@ -98,6 +112,15 @@ filter :only => [/.*.markdown$/]
98
112
  filter :exclude => [/.*.erb$/]
99
113
  ```
100
114
 
115
+ #### sort
116
+
117
+ With `sort`, you can specify wheter you want to sort the sources *ascending* (default) or *descending* based on the file name:
118
+
119
+ ```
120
+ sort :descending
121
+ ```
122
+
123
+
101
124
  #### apply
102
125
 
103
126
  The mightiest of all commands, `apply`, can be used to execute custom code (so-called *modules*) in the context of the current set of sources. Modules are searched for in the `modules/` folder of your project and need to be included in the Deplotfle (`use :teaser` for `teaser.rb`). For our basic blog, we may want to shorten the text displayed on the front page and display a link to the post page:
@@ -151,13 +174,13 @@ There are three types of modules: the filter, the preprocessor, the processor mo
151
174
 
152
175
  ## Planned features
153
176
 
154
- * Ability to use custom renderer code (block and module)
177
+ * Ability to use custom renderer modules
155
178
  * Non-media asset processing (compiling, compressing, concatenating) for files written in LESS, SASS, CoffeScript etc.
156
179
  * Filter: keep or discard file when one or more, but not necessarily all conditions are met (considered bug)
157
180
  * Automatic rebuilding using [guard][guard]
158
181
  * Media resizing and conversion
159
182
  * Partials (for more modular layouts)
160
- * Ability to sort source files
183
+ * Expand sort functionality
161
184
 
162
185
  Please submit feature requests and bugfixes in the issue tracker.
163
186
 
@@ -165,5 +188,5 @@ Please submit feature requests and bugfixes in the issue tracker.
165
188
 
166
189
  See LICENSE file.
167
190
 
168
- [tilt]: https://github.com/rtomayko/ti
169
- [guard]: https://github.com/guard/guardlt
191
+ [tilt]: https://github.com/rtomayko/tilt
192
+ [guard]: https://github.com/guard/guard
data/bin/deplot CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
 
5
5
  require 'thor'
6
6
  require 'fileutils'
@@ -45,6 +45,23 @@ class DeplotRenderer
45
45
  @sources = (Dir.glob(base_dir + "*") - [".", "..", ".DS_STORE"]).collect { |file| {:filename => file} }
46
46
  @base_dir = base_dir
47
47
  @layout = ""
48
+ @sort_options = {
49
+ :reverse => false
50
+ }
51
+ end
52
+
53
+ # Sort sources based on file name
54
+ def sort *args
55
+ #args.uniq!
56
+ @sort_options[:reverse] = false if args.include? :ascending
57
+ @sort_options[:reverse] = true if args.include? :descending
58
+ end
59
+
60
+ # Prerender: apply sort options
61
+ def prerender
62
+ puts @sort_options[:reverse]
63
+ puts @sources
64
+ @sources.reverse! if @sort_options[:reverse]
48
65
  end
49
66
 
50
67
  # Filter out sources based on file name
@@ -75,6 +92,7 @@ class DeplotMediaRenderer < DeplotRenderer
75
92
  end
76
93
 
77
94
  def copy_to output_dir
95
+ prerender
78
96
  puts "Copying files..."
79
97
  FileUtils.mkdir_p(output_dir)
80
98
  @sources.each do |source|
@@ -102,7 +120,10 @@ end
102
120
 
103
121
  # Document renderer
104
122
  class DeplotDocumentRenderer < DeplotRenderer
123
+ attr_accessor :renderer
124
+
105
125
  def initialize base_dir
126
+ @renderer = nil
106
127
  puts "Documents renderer initialized.".green
107
128
  super
108
129
  end
@@ -117,18 +138,23 @@ class DeplotDocumentRenderer < DeplotRenderer
117
138
  end
118
139
 
119
140
  def render
141
+ prerender
120
142
  read if @read == false
121
143
  puts "Rendering..."
122
144
  @rendered = true
123
- @sources.each do |source|
124
- renderer = Tilt[source[:filename]]
125
- unless renderer.nil?
126
- source[:content] = renderer.new do
127
- source[:content]
128
- end.render context
129
- else
130
- alert "No Tilt renderer found for '#{source[:filename]}', falling back to echo."
145
+ if @renderer.nil?
146
+ @sources.each do |source|
147
+ renderer = Tilt[source[:filename]]
148
+ unless renderer.nil?
149
+ source[:content] = renderer.new do
150
+ source[:content]
151
+ end.render context
152
+ else
153
+ alert "No Tilt renderer found for '#{source[:filename]}', falling back to echo."
154
+ end
131
155
  end
156
+ else
157
+ @renderer.call(@sources)
132
158
  end
133
159
  end
134
160
 
@@ -266,9 +292,14 @@ end
266
292
  end
267
293
  end
268
294
  end
295
+ self.class.send :define_method, "render" do |&block|
296
+ unless $current_instance.nil?
297
+ $current_instance.send("renderer=", block)
298
+ end
299
+ end
269
300
 
270
301
  # Basic methods
271
- ["filter", "apply", "copy_to"].each do |method_name|
302
+ ["filter", "apply", "copy_to", "sort"].each do |method_name|
272
303
  self.class.send :define_method, method_name do |*args|
273
304
  unless $current_instance.nil?
274
305
  $current_instance.context = binding.eval("self")
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'deplot'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2013-03-01'
5
5
  s.summary = "A lightweight and very extensible static web site generator"
6
6
  s.description = %{
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: