sinatra-wardrobe 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinatra-wardrobe.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Sinatra Wardrobe
2
+
3
+ A way to dress up Sinatra with static file routing based on a few params.
4
+
5
+ Require in your `Gemfile`
6
+
7
+ ```ruby
8
+ gem 'sinatra-wardrobe'
9
+ ```
10
+
11
+ And use it with the `suit_up!` method.
12
+
13
+ ```ruby
14
+ suit_up! directories: './views', extensions: '.md'
15
+ ```
16
+
17
+ Currently it only supports `.erb`, `.md` and `.markdown` but there are more to come.
18
+
19
+ [MIT Licensed](http://evan.mit-license.org/)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,77 @@
1
+ require "sinatra-wardrobe/version"
2
+
3
+ module Sinatra
4
+ module Wardrobe
5
+ @@hats = []
6
+
7
+ # just the array of Hash objects
8
+ def hats
9
+ @@hats
10
+ end
11
+
12
+ # this might not be necessary
13
+ def hat_rack(list_type = 'ul')
14
+ hatrack = "<#{ list_type }>"
15
+
16
+ @@hats.each do |hat|
17
+ hatrack << "<li><a href='#{ hat[:path] }'>#{ hat[:title] }</a></li>"
18
+ end
19
+
20
+ hatrack << "</#{ list_type }>"
21
+ end
22
+
23
+ # because it's a declaration!
24
+ def suit_up!(options = {})
25
+ options = {
26
+ directories: ['./views'],
27
+ extensions: ['.md'],
28
+ excludes: ['layout.erb'],
29
+ layout_engine: :erb
30
+ }.merge(options)
31
+
32
+ [:extensions, :excludes, :directories].each do |option|
33
+ if options[option].is_a? String
34
+ options[option] = [options[option]]
35
+ end
36
+ end
37
+
38
+ directories_regexp = Regexp.new(options[:directories].join('|'))
39
+
40
+ options[:directories].each do |dir|
41
+ options[:extensions].each do |ext|
42
+ Dir.glob("#{ dir }/**/*#{ ext }") do |file|
43
+ file_name = file.gsub(directories_regexp, '')
44
+
45
+ $stdout.puts "File found #{ file } and file_name is #{ file_name }"
46
+
47
+ next if options[:excludes].include?(file_name.gsub(/\//, ''))
48
+
49
+ file_route = file_name.gsub(ext, '')
50
+ file_title = file_route.split('/').last
51
+ file_title = file_title.gsub(/\-/, ' ').split(' ').each do |word|
52
+ word.capitalize!
53
+ end.join(' ')
54
+
55
+ @@hats << { path: file_route, title: file_title, extension: ext }
56
+ end
57
+ end
58
+ end
59
+
60
+ # bind some GET requests
61
+ @@hats.each do |link|
62
+ get link[:path] do
63
+ @title = link[:title]
64
+
65
+ case link[:extension]
66
+ when '.md', '.markdown'
67
+ markdown link[:path].to_sym, layout_engine: options[:layout_engine]
68
+ when '.erb'
69
+ erb link[:path].to_sym, layout_engine: options[:layout_engine]
70
+ end
71
+ end
72
+ end # /@@hats.each
73
+ end # /suit_up!
74
+ end # /Wardrobe
75
+
76
+ register Wardrobe
77
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Wardrobe
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sinatra-wardrobe/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sinatra-wardrobe"
7
+ s.version = Sinatra::Wardrobe::VERSION
8
+ s.authors = ["Evan Lecklider"]
9
+ s.email = ["evan.lecklider@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A quick and dirty static file router for Sinatra.}
12
+ s.description = %q{A quick and dirty static file router for Sinatra.}
13
+
14
+ s.rubyforge_project = "sinatra-wardrobe"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "sinatra"
24
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-wardrobe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Evan Lecklider
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: &70151210928240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70151210928240
25
+ description: A quick and dirty static file router for Sinatra.
26
+ email:
27
+ - evan.lecklider@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/sinatra-wardrobe.rb
37
+ - lib/sinatra-wardrobe/version.rb
38
+ - sinatra-wardrobe.gemspec
39
+ homepage: ''
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project: sinatra-wardrobe
59
+ rubygems_version: 1.8.15
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: A quick and dirty static file router for Sinatra.
63
+ test_files: []