sinatra-wardrobe 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,6 +14,21 @@ And use it with the `suit_up!` method.
14
14
  suit_up! directories: './views', extensions: '.md'
15
15
  ```
16
16
 
17
+ Or, for a little more control:
18
+
19
+ ```ruby
20
+ suit_up! directories: ['./views/blog', './views/static'], extensions: ['.md', '.erb'], excludes: 'layout.erb', layout_engine: :erb
21
+ ```
22
+
23
+ ## Defaults
24
+
25
+ By default, `Sinatra::Wardrobe` will look for files with a `.md` extension in the `./views` directory, ignoring `layout.erb` and assuming a `layout_engine` of `:erb`.
26
+
17
27
  Currently it only supports `.erb`, `.md` and `.markdown` but there are more to come.
18
28
 
29
+ ## Helpers
30
+
31
+ * `hats` will return the array of Hash objects that `Sinatra::Wardrobe` uses to bind the `get` requests and serve your files.
32
+ * `hat_rack` is an HTML helper that generates an (by default) unordered list with links to each of the files in the `hats` array.
33
+
19
34
  [MIT Licensed](http://evan.mit-license.org/)
@@ -23,10 +23,10 @@ module Sinatra
23
23
  # because it's a declaration!
24
24
  def suit_up!(options = {})
25
25
  options = {
26
- directories: ['./views'],
27
- extensions: ['.md'],
28
- excludes: ['layout.erb'],
29
- layout_engine: :erb
26
+ :directories => ['./views'],
27
+ :extensions => ['.md'],
28
+ :excludes => ['layout.erb'],
29
+ :layout_engine => :erb
30
30
  }.merge(options)
31
31
 
32
32
  [:extensions, :excludes, :directories].each do |option|
@@ -35,15 +35,15 @@ module Sinatra
35
35
  end
36
36
  end
37
37
 
38
+ # a little Regexp to filter out exclusions
38
39
  directories_regexp = Regexp.new(options[:directories].join('|'))
39
40
 
41
+ # loop and then loop and then GLOB!!
40
42
  options[:directories].each do |dir|
41
43
  options[:extensions].each do |ext|
42
44
  Dir.glob("#{ dir }/**/*#{ ext }") do |file|
43
45
  file_name = file.gsub(directories_regexp, '')
44
46
 
45
- $stdout.puts "File found #{ file } and file_name is #{ file_name }"
46
-
47
47
  next if options[:excludes].include?(file_name.gsub(/\//, ''))
48
48
 
49
49
  file_route = file_name.gsub(ext, '')
@@ -52,7 +52,7 @@ module Sinatra
52
52
  word.capitalize!
53
53
  end.join(' ')
54
54
 
55
- @@hats << { path: file_route, title: file_title, extension: ext }
55
+ @@hats << { :path => file_route, :title => file_title, :extension => ext }
56
56
  end
57
57
  end
58
58
  end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Wardrobe
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-wardrobe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-07 00:00:00.000000000 Z
12
+ date: 2012-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70151210928240 !ruby/object:Gem::Requirement
16
+ requirement: &70102351546200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70151210928240
24
+ version_requirements: *70102351546200
25
25
  description: A quick and dirty static file router for Sinatra.
26
26
  email:
27
27
  - evan.lecklider@gmail.com