gumdrop 0.4.0 → 0.5

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.
Files changed (81) hide show
  1. data/.gitignore +2 -2
  2. data/ChangeLog.md +17 -0
  3. data/Notes.md +8 -1
  4. data/lib/gumdrop.rb +82 -45
  5. data/lib/gumdrop/build.rb +10 -0
  6. data/lib/gumdrop/cli.rb +119 -33
  7. data/lib/gumdrop/context.rb +6 -1
  8. data/lib/gumdrop/deferred_loader.rb +54 -15
  9. data/lib/gumdrop/dsl.rb +8 -2
  10. data/lib/gumdrop/generator.rb +41 -2
  11. data/lib/gumdrop/version.rb +1 -1
  12. data/{lib/gumdrop/template/default → templates/backbone}/Gemfile +6 -4
  13. data/templates/backbone/Gumdrop +119 -0
  14. data/{lib/gumdrop/template → templates}/backbone/Rakefile +0 -0
  15. data/{lib/gumdrop/template → templates}/backbone/app/app.js.coffee +0 -0
  16. data/{lib/gumdrop/template → templates}/backbone/app/init.js.coffee +0 -0
  17. data/{lib/gumdrop/template → templates}/backbone/app/models/.gitkeep +0 -0
  18. data/{lib/gumdrop/template → templates}/backbone/app/utils/index.js.coffee +0 -0
  19. data/{lib/gumdrop/template → templates}/backbone/app/views/home.js.coffee +0 -0
  20. data/{lib/gumdrop/template → templates}/backbone/app/views/styles/home.scss +0 -0
  21. data/{lib/gumdrop/template → templates}/backbone/app/views/templates/home.mustache +0 -0
  22. data/{lib/gumdrop/template → templates}/backbone/config.ru +0 -0
  23. data/{lib/gumdrop/template/backbone/lib/javascript → templates/backbone/lib}/all.js.coffee +0 -0
  24. data/{lib/gumdrop/template/backbone/lib/javascript → templates/backbone/lib}/backbone.js +0 -0
  25. data/{lib/gumdrop/template/backbone/lib/javascript → templates/backbone/lib}/hogan.js +0 -0
  26. data/{lib/gumdrop/template/backbone/lib/javascript → templates/backbone/lib}/jquery.js +0 -0
  27. data/{lib/gumdrop/template/backbone/lib/javascript → templates/backbone/lib}/underscore.js +0 -0
  28. data/{lib/gumdrop/template → templates}/backbone/powrc +0 -0
  29. data/{lib/gumdrop/template/backbone/source/default.htaccess → templates/backbone/source/default.htaccess.erb} +4 -0
  30. data/{examples/simple → templates/backbone}/source/favicon.ico +0 -0
  31. data/{lib/gumdrop/template → templates}/backbone/source/feed.xml.builder.txt +8 -8
  32. data/{lib/gumdrop/template → templates}/backbone/source/index.html.erb +0 -0
  33. data/{lib/gumdrop/template → templates}/backbone/source/theme/screen.css.sass +0 -0
  34. data/{lib/gumdrop/template → templates}/backbone/source/theme/scripts/app.js.coffee +0 -0
  35. data/{examples/simple → templates/backbone}/source/theme/styles/_tools.scss +0 -0
  36. data/{lib/gumdrop/template → templates}/backbone/source/theme/templates/app.template.slim +1 -1
  37. data/{lib/gumdrop/template → templates}/backbone/source/theme/templates/site.template.slim +3 -3
  38. data/{lib/gumdrop/template/backbone → templates/default}/Gemfile +6 -4
  39. data/templates/default/Gumdrop +109 -0
  40. data/{lib/gumdrop/template → templates}/default/Rakefile +0 -0
  41. data/{lib/gumdrop/template → templates}/default/config.ru +0 -0
  42. data/{lib/gumdrop/template → templates}/default/powrc +0 -0
  43. data/{lib/gumdrop/template/default/source/default.htaccess → templates/default/source/default.htaccess.erb} +11 -1
  44. data/{lib/gumdrop/template/backbone → templates/default}/source/favicon.ico +0 -0
  45. data/{lib/gumdrop/template → templates}/default/source/feed.xml.builder.txt +8 -8
  46. data/templates/default/source/index.html.erb +1 -0
  47. data/{lib/gumdrop/template → templates}/default/source/theme/screen.css.sass +0 -0
  48. data/{lib/gumdrop/template → templates}/default/source/theme/scripts/app.js.coffee +0 -0
  49. data/{lib/gumdrop/template/backbone → templates/default}/source/theme/styles/_tools.scss +0 -0
  50. data/{lib/gumdrop/template → templates}/default/source/theme/templates/site.template.slim +3 -3
  51. metadata +56 -83
  52. data/examples/simple/Gemfile +0 -22
  53. data/examples/simple/Rakefile +0 -42
  54. data/examples/simple/config.ru +0 -15
  55. data/examples/simple/data/config.yml +0 -10
  56. data/examples/simple/data/posts.yamldb +0 -28
  57. data/examples/simple/lib/site.rb +0 -24
  58. data/examples/simple/lib/view_helpers.rb +0 -17
  59. data/examples/simple/source/.htaccess +0 -16
  60. data/examples/simple/source/_pager_control.html.erb +0 -14
  61. data/examples/simple/source/_sidebar.html.haml +0 -2
  62. data/examples/simple/source/feed.xml.builder +0 -23
  63. data/examples/simple/source/index.html.erb +0 -4
  64. data/examples/simple/source/posts.generator.rb +0 -11
  65. data/examples/simple/source/posts/index.html.erb +0 -6
  66. data/examples/simple/source/theme/screen.css.scss +0 -10
  67. data/examples/simple/source/theme/scripts/app.js.coffee +0 -0
  68. data/examples/simple/source/theme/templates/post.template.haml +0 -3
  69. data/examples/simple/source/theme/templates/post_page.template.haml +0 -6
  70. data/examples/simple/source/theme/templates/site.template.haml +0 -33
  71. data/examples/simple/source/theme/templates/test.template.erb +0 -1
  72. data/lib/gumdrop/template/backbone/data/config.yml +0 -4
  73. data/lib/gumdrop/template/backbone/lib/site.rb +0 -62
  74. data/lib/gumdrop/template/backbone/lib/stitch_compilers.rb +0 -1
  75. data/lib/gumdrop/template/backbone/lib/view_helpers.rb +0 -17
  76. data/lib/gumdrop/template/default/data/config.yml +0 -4
  77. data/lib/gumdrop/template/default/lib/site.rb +0 -50
  78. data/lib/gumdrop/template/default/lib/view_helpers.rb +0 -17
  79. data/lib/gumdrop/template/default/source/favicon.ico +0 -0
  80. data/lib/gumdrop/template/default/source/index.html.erb +0 -1
  81. data/lib/gumdrop/template/default/source/theme/styles/_tools.scss +0 -434
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
1
  .DS_Store
2
2
  *.gem
3
- *.lock
4
3
  examples/**/output
5
- .sass-cache
4
+ .sass-cache
5
+ old_examples
@@ -1,3 +1,20 @@
1
+ # v0.5
2
+ - Gumdrop projects now require a `Gumdrop` file at the root -- contents are what you used to put in lib/site.rb.
3
+ - Added new `configure` and `view_helpers` methods for use in `Gumdrop` site file.
4
+ - Smarter CLI, knows when you're in a gumdrop site or not.
5
+ - Local templates supported for new sites (looks under ~/.gumdrop/templates)
6
+ - You can list installed templates using `gumdrop --list`
7
+ - You can install the current site as a local template using `gumdrop -t new_template_name` in a site folder.
8
+ - Data folder path is now configurable: `Gumdrop.config.data_dir` or `set :data_dir, "PATH"`
9
+ - Added `data.site` and `data.site_all` to `DefferedLoader`. Useful for listing all non-grey-listed files or all files.
10
+ - Data will now load from data/COLLECTION_NAME/*.(json | yaml | yml). Loads as an array array of all entries, adds a key '_id' that's the base filename.
11
+ - Initial `redirect` options for use in generate blocks.
12
+ - Extra stitch generator options:
13
+ - `compress` takes `:jsmin`, `:yuic`, or `:uglify` now. (`true` defaults to `:jsmin`)
14
+ - `obfuscate: true|false` -- Sets munging/mangling for compressors that support it.
15
+ - `keep_src: true|false` -- Creates a second filename with :source_postfix added to the end of the filename
16
+ - `source_postfix: "-src"`
17
+
1
18
  # v0.4
2
19
  - Added support for special dev proxy at /-proxy/ENDPOINT_URL -- Useful for working with external (non-CORS) apis/websites. Enabled by default. To disable, set Gumdrop.config.proxy_enabled= false
3
20
 
data/Notes.md CHANGED
@@ -1,4 +1,11 @@
1
1
  # Future Features/Changes
2
2
  - HTML Manifest generation??
3
3
  - Some kind of admin? What would that even do?
4
- - proxy support
4
+ - If you could specify a 'prototype' for data collections, could be cool.
5
+
6
+
7
+ # TODO:
8
+ - New/Update Doc Site
9
+ - API for retrieving pages and pages under a path (simple query)
10
+ - Cleanup api and verbiage around blacklisting and ignoring
11
+ - YamlDoc support (in data anyway)
@@ -10,11 +10,11 @@ DEFAULT_OPTIONS= {
10
10
  auto_run: false,
11
11
  force_reload: false,
12
12
  proxy_enabled: true,
13
- log_level: :info,
14
- root: ".",
15
13
  output_dir: "./output",
16
14
  lib_dir: "./lib",
17
15
  source_dir: "./source",
16
+ data_dir: './data',
17
+ log_level: :info,
18
18
  log: 'logs/build.log'
19
19
  }
20
20
 
@@ -49,6 +49,7 @@ module Gumdrop
49
49
  :layouts,
50
50
  :generators,
51
51
  :partials,
52
+ :redirects,
52
53
  :config,
53
54
  :data,
54
55
  :content_filters,
@@ -58,53 +59,51 @@ module Gumdrop
58
59
  :last_run
59
60
 
60
61
  def run(opts={})
61
- # Opts
62
- Gumdrop.config.merge! opts
63
-
64
- root= File.expand_path Gumdrop.config.root
65
- src= File.expand_path Gumdrop.config.source_dir #File.join root, 'source'
66
- lib_path= File.expand_path Gumdrop.config.lib_dir
67
- $: << lib_path # "#{root}/lib"
68
- if File.exists? File.join(lib_path,"view_helpers.rb")
69
- # In server mode, we want to reload it every time... right?
70
- load File.join(lib_path,"view_helpers.rb")
71
- end
62
+ site_file= Gumdrop.fetch_site_file
72
63
 
73
- @site = Hash.new {|h,k| h[k]= nil }
74
- @layouts = Hash.new {|h,k| h[k]= nil }
75
- @generators = Hash.new {|h,k| h[k]= nil }
76
- @partials = Hash.new {|h,k| h[k]= nil }
77
- @root_path = root.split '/'
78
- @source_path = src.split '/'
79
- @data = Gumdrop::DeferredLoader.new()
80
- @last_run = Time.now
81
-
82
- begin
83
- @log = Logger.new Gumdrop.config.log, 'daily'
84
- rescue
85
- @log = Logger.new STDOUT
86
- end
87
- @log.formatter = proc do |severity, datetime, progname, msg|
88
- "#{datetime}: #{msg}\n"
89
- end
64
+ unless site_file.nil?
65
+ @generators = Hash.new {|h,k| h[k]= nil }
66
+ @content_filters = []
67
+ @blacklist = []
68
+ @greylist = []
69
+ @redirects = []
90
70
 
91
- @content_filters= []
92
- @blacklist = []
93
- @greylist = []
94
-
95
- if File.exists? File.join(lib_path, "site.rb") # "#{root}/lib/site.rb"
96
71
  # In server mode, we want to reload it every time... right?
97
- source= IO.readlines( File.join(lib_path,"site.rb") ).join('')
98
- DSL.class_eval source
99
- # TODO: Find a good place to define where source folder should be defined.
100
- # In case the source folder has changed.
72
+ load_site_file site_file
73
+
74
+ Gumdrop.config.merge! opts # These beat those in the Gumdrop file?
75
+
76
+ root= File.expand_path File.dirname(site_file)
77
+ Dir.chdir root
78
+
101
79
  src= File.expand_path Gumdrop.config.source_dir #File.join root, 'source'
102
- @source_path= src.split '/'
103
- end
80
+ lib_path= File.expand_path Gumdrop.config.lib_dir
81
+
82
+ @root_path = root.split '/'
83
+ @source_path = src.split '/'
84
+ @site = Hash.new {|h,k| h[k]= nil }
85
+ @layouts = Hash.new {|h,k| h[k]= nil }
86
+ @partials = Hash.new {|h,k| h[k]= nil }
87
+ @data = Gumdrop::DeferredLoader.new( Gumdrop.config.data_dir )
88
+ @last_run = Time.now
89
+
90
+ begin
91
+ @log = Logger.new Gumdrop.config.log, 'daily'
92
+ rescue
93
+ @log = Logger.new STDOUT
94
+ end
95
+ @log.formatter = proc do |severity, datetime, progname, msg|
96
+ "#{datetime}: #{msg}\n"
97
+ end
104
98
 
105
- Build.run root, src, opts
99
+ Build.run root, src, opts
100
+
101
+ puts "Done."
106
102
 
107
- puts "Done."
103
+ else
104
+ puts "Not in a valid Gumdrop site directory."
105
+
106
+ end
108
107
  end
109
108
 
110
109
  # levels: info, warning, error
@@ -112,18 +111,56 @@ module Gumdrop
112
111
  ll= Gumdrop.config.log_level
113
112
  case level
114
113
  when :info
115
- #puts msg if ll == :info
116
114
  @log.info msg
117
115
  when :warning
118
- #puts msg if ll == :info or ll == :warning
119
116
  @log.warn msg
120
117
  else
121
118
  puts msg
122
119
  @log.error msg
123
120
  end
124
121
  end
122
+
123
+ def in_site_folder?(filename="Gumdrop")
124
+ !fetch_site_file(filename).nil?
125
+ end
126
+
127
+ def load_site_file(site_file=nil)
128
+ site_file= fetch_site_file if site_file.nil?
129
+ source= IO.readlines( site_file ).join('')
130
+ DSL.class_eval source
131
+ end
132
+
133
+ def fetch_site_file(filename="Gumdrop")
134
+ here= Dir.pwd
135
+ found= File.file? File.join( here, filename )
136
+ while !found and File.directory?(here) and File.dirname(here).length > 3
137
+ here= File.expand_path File.join(here, '../')
138
+ found= File.file? File.join( here, filename )
139
+ end
140
+ if found
141
+ File.expand_path File.join(here, filename)
142
+ else
143
+ nil
144
+ end
145
+ end
146
+
147
+ def site_folder(filename="Gumdrop")
148
+ File.dirname( fetch_site_file( filename ) )
149
+ end
150
+
125
151
  end
126
152
 
153
+
127
154
  Gumdrop.config= Gumdrop::HashObject.new(DEFAULT_OPTIONS)
155
+
156
+
157
+ module Configurator
158
+ class << self
159
+ def set(key,value)
160
+ # puts "Setting Gumdrop.config.#{key} = #{value}"
161
+ Gumdrop.config[key.to_sym]= value
162
+ end
163
+ end
164
+ end
128
165
 
129
166
  end
@@ -17,6 +17,15 @@ module Gumdrop
17
17
  end
18
18
 
19
19
  def build_tree
20
+ Gumdrop.report "[Scanning from #{src}]", :info
21
+ # Report blacklists and greylists
22
+ Gumdrop.blacklist.each do |path|
23
+ Gumdrop.report " blacklist: #{path}", :info
24
+ end
25
+ Gumdrop.greylist.each do |path|
26
+ Gumdrop.report " greylist: #{path}", :info
27
+ end
28
+
20
29
  # Scan Filesystem
21
30
  #puts "Running in: #{root}"
22
31
  Dir.glob("#{src}/**/*", File::FNM_DOTMATCH).each do |path|
@@ -47,6 +56,7 @@ module Gumdrop
47
56
  end
48
57
 
49
58
  def run_generators
59
+ Gumdrop.report "[Executing Generators]", :info
50
60
  Gumdrop.generators.each_pair do |path, generator|
51
61
  generator.execute()
52
62
  end
@@ -1,41 +1,102 @@
1
1
 
2
2
  require 'trollop'
3
3
 
4
- opts = Trollop::options do
5
- banner ""
6
- banner <<-EOS
7
- Gumdrop v#{ Gumdrop::VERSION }
8
- The simple, static, CMS.
9
-
10
- Examples:
11
- gumdrop --create my_new_site --template backbone
12
- Is the same as:
13
- gumdrop -c my_new_site -t backbone
14
-
15
- Options:
4
+ banner_text= <<-EOS
5
+
6
+ Gumdrop v#{ Gumdrop::VERSION }
7
+ The simple, sweet, static CMS.
8
+
16
9
  EOS
10
+
11
+ opts = Trollop::options do
12
+ banner banner_text
13
+
17
14
  opt :verbose,"Verbose output"
18
15
  opt :debug, "Enable debugging output"
19
- opt :quiet, "No output"
20
- opt :create, "Create a gumdrop project", :type=>String
21
- opt :template, "Specify template to use for new project (default || backbone)", :type=>String, :default=>'default'
22
- opt :build, "Build HTML output"
23
- opt :server, "Runs development server"
24
- opt :port, "Specifies port to run server on", :type=>:int
25
- opt :reload, "Force reloading on dev server"
16
+ opt :quiet, "No console output"
17
+
18
+ if Gumdrop.in_site_folder?
19
+ banner <<-EOS
20
+
21
+ Examples:
22
+ gumdrop --build
23
+ gumdrop -b
24
+ gumdrop --new Post
25
+ gumdrop --server
26
+ gumdrop -s -p 8080 -r
27
+
28
+ Options:
29
+ EOS
30
+ opt :build, "Build HTML output"
31
+ opt :new, "Create new data item (specify collection name)", :type=>String
32
+ opt :server, "Runs development server"
33
+ opt :port, "Specifies port to run server on", :type=>:int
34
+ opt :reload, "Force reloading on dev server"
35
+ opt :template, "Create local template from this site (specify template name)", :type=>String
36
+ else
37
+ banner <<-EOS
38
+
39
+ Examples:
40
+ gumdrop --create my_site
41
+ gumdrop -c new_site --template backbone
42
+
43
+ Options:
44
+ EOS
45
+ opt :create, "Create a gumdrop project", :type=>String
46
+ opt :template, "Template to create new project from", :type=>String, :default=>'default'
47
+ opt :list, "List available templates"
48
+ end
49
+
26
50
  end
27
51
 
28
- # Trollop::die :volume, "must be non-negative" if opts[:volume] < 0
29
- # Trollop::die :file, "must exist" unless File.exist?(opts[:file]) if opts[:file]
30
52
 
31
- unless opts[:create_given] or opts[:build_given] or opts[:server_given]
32
- Trollop::die "You must specify one of --create --build --server"
53
+ unless opts[:create_given] or opts[:build_given] or opts[:server_given] or opts[:new_given] or opts[:template_given] or opts[:list_given]
54
+ puts banner_text
55
+ Trollop::die "No commands specified"
33
56
  end
34
57
 
35
58
 
36
- if opts[:create_given]
59
+
60
+ if opts[:build_given]
61
+ puts banner_text unless opts[:quiet_given]
62
+ Gumdrop.run(opts)
63
+
64
+
65
+ elsif opts[:server_given]
66
+ puts banner_text unless opts[:quiet_given]
67
+ Gumdrop.config.auto_run= true
68
+ Gumdrop.config.force_reload= opts[:reload_given]
69
+ Gumdrop::Server
70
+
71
+
72
+ elsif opts[:list_given]
73
+ # List templates
74
+ puts banner_text unless opts[:quiet_given]
75
+ here= File.dirname(__FILE__)
76
+ lib_dir= File.expand_path File.join(here, '../../templates', '*')
77
+ user_dir= File.expand_path File.join("~", ".gumdrop", "templates", "*")
78
+ puts "Gem Templates:"
79
+ Dir[lib_dir].each do |name|
80
+ puts " #{File.basename name}" if File.directory?(name)
81
+ end
82
+ puts "Local Templates:"
83
+ Dir[user_dir].each do |name|
84
+ puts " #{File.basename name}" if File.directory?(name)
85
+ end
86
+
87
+
88
+ elsif opts[:new_given]
89
+ puts banner_text unless opts[:quiet_given]
90
+ puts "Not implemented yet..."
91
+
92
+
93
+ elsif opts[:create_given]
94
+ puts banner_text unless opts[:quiet_given]
95
+
37
96
  require 'fileutils'
38
97
  here= File.dirname(__FILE__)
98
+ lib_root= File.expand_path File.join(here, '../../')
99
+ user_gumdrop_dir= File.expand_path File.join("~", ".gumdrop")
39
100
  there= File.expand_path( opts[:create] )
40
101
  template_name = opts[:template]
41
102
 
@@ -45,24 +106,49 @@ if opts[:create_given]
45
106
  FileUtils.mkdir_p there
46
107
  end
47
108
 
48
- if File.directory? File.join(here, 'template', template_name)
109
+ # from gem...
110
+ if File.directory? File.join(lib_root, 'templates', template_name)
111
+ # FileUtils.cp_r Dir[File.join(here, "template", template_name, "*")], there
112
+ puts "Creating gumdrop project (from template:#{template_name})"
113
+ puts " #{there}"
114
+ FileUtils.cp_r File.join(lib_root, "templates", template_name, "."), there
115
+ puts "Done."
116
+
117
+ # local template...
118
+ elsif File.directory? File.join(user_gumdrop_dir, 'templates', template_name)
49
119
  # FileUtils.cp_r Dir[File.join(here, "template", template_name, "*")], there
50
- puts "Creating gumdrop project based on #{template_name} template at #{there}"
51
- FileUtils.cp_r File.join(here, "template", template_name, "."), there
120
+ puts "Creating gumdrop project (from local template:#{template_name})"
121
+ puts " #{there}"
122
+ FileUtils.cp_r File.join(user_gumdrop_dir, "templates", template_name, "."), there
52
123
  puts "Done."
124
+
53
125
  else
54
126
  puts "Invalid template '#{template_name}'!"
55
127
  end
128
+
129
+
130
+ elsif opts[:template_given]
131
+ # Save as template...
132
+ puts banner_text unless opts[:quiet_given]
133
+ template= opts[:template]
134
+ template_path = File.expand_path File.join('~', '.gumdrop', 'templates', template)
135
+ if File.exists? template_path
136
+ puts "A template named '#{template}' already exists!"
137
+ else
138
+ require 'fileutils'
139
+ puts "Creating template: #{template}"
140
+ puts " ~/.gumdrop/templates/#{template}"
141
+ site_root= Gumdrop.site_folder
142
+ FileUtils.mkdir_p File.dirname(template_path)
143
+ FileUtils.cp_r File.join(site_root, "."), template_path
144
+ puts "Done."
145
+ end
56
146
 
57
- elsif opts[:build_given]
58
- Gumdrop.run(opts)
59
147
 
60
- elsif opts[:server_given]
61
- Gumdrop.config.auto_run= true
62
- Gumdrop.config.force_reload= opts[:reload_given]
63
- Gumdrop::Server
148
+
64
149
 
65
150
  else
151
+ puts banner_text
66
152
  require 'pp'
67
153
  puts "Unknown options"
68
154
  pp opts
@@ -25,7 +25,7 @@ module Gumdrop
25
25
 
26
26
  def url(path)
27
27
  path= path[1..-1] if path.starts_with?('/')
28
- "#{data.config.url}/#{path}"
28
+ "#{Gumdrop.config.site_url}/#{path}"
29
29
  end
30
30
 
31
31
  def slug
@@ -62,6 +62,11 @@ module Gumdrop
62
62
  def data
63
63
  Gumdrop.data
64
64
  end
65
+
66
+ # Access to settings from configure block
67
+ def config
68
+ Gumdrop.config
69
+ end
65
70
 
66
71
  def reset_data(preset={})
67
72
  # TODO: Add a setting for reloading data on every request/page
@@ -22,8 +22,9 @@ module Gumdrop
22
22
  class DeferredLoader
23
23
  attr_reader :cache
24
24
 
25
- def initialize
25
+ def initialize(data_dir="data")
26
26
  #puts "@!@"
27
+ @dir= data_dir
27
28
  @cache= {}
28
29
  @persisted= {}
29
30
  end
@@ -38,8 +39,28 @@ module Gumdrop
38
39
  @persisted[key]= value #unless opts[:persist] == false
39
40
  end
40
41
 
41
- def reset
42
- @cache= @persisted.clone #Hash.new(@persisted) #{|h,k| h[k]= load_data(k) }
42
+ def reset(hard=false)
43
+ if hard
44
+ @cache={}
45
+ @persisted={}
46
+ else
47
+ @cache= @persisted.clone #Hash.new(@persisted) #{|h,k| h[k]= load_data(k) }
48
+ end
49
+ end
50
+
51
+ def site
52
+ # TODO: This is not a great place for this!
53
+ site= Hash.new {|h,k| h[k]= nil }
54
+ Gumdrop.site.keys.sort.each do |path|
55
+ unless Gumdrop.greylist.any? {|p| path.starts_with?(p) }
56
+ site[path]= Gumdrop.site[path]
57
+ end
58
+ end
59
+ site
60
+ end
61
+
62
+ def site_all
63
+ Gumdrop.site
43
64
  end
44
65
 
45
66
  def pager_for(key, opts={})
@@ -59,6 +80,7 @@ module Gumdrop
59
80
 
60
81
  def cache_or_load_data(key)
61
82
  @cache[key]= load_data(key) unless @cache.has_key? key
83
+ @persisted[key]= @cache[key] # New persist data loaded from file?
62
84
  end
63
85
 
64
86
  def load_data(key)
@@ -72,26 +94,43 @@ module Gumdrop
72
94
  end
73
95
  end
74
96
  docs
97
+ elsif File.extname(path) == ""
98
+ all=[]
99
+ Dir[ File.join( "#{path}", "{*.yaml,*.json,*.yml}" ) ].each do |filename|
100
+ # Gumdrop.report ">> Loading data file: #{filename}"
101
+ id= File.basename filename
102
+ raw_hash= YAML.load_file(filename)
103
+ raw_hash['_id']= id
104
+ obj_hash= hashes2ostruct( raw_hash )
105
+ all << obj_hash
106
+ end
107
+ all
75
108
  else
76
109
  hashes2ostruct( YAML.load_file(path) )
77
110
  end
78
111
  end
79
112
 
80
- # TODO: Support './data/collection_name/*.(yaml|json)' data loading?
81
-
82
113
  def get_filename(path)
83
- if File.exists? "data/#{path}.json"
84
- "data/#{path}.json"
85
- elsif File.exists? "data/#{path}.yml"
86
- "data/#{path}.yml"
87
- elsif File.exists? "data/#{path}.yaml"
88
- "data/#{path}.yaml"
89
- elsif File.exists? "data/#{path}.yamldb"
90
- "data/#{path}.yamldb"
114
+ if File.exists? local_path_to("#{path}.json")
115
+ local_path_to "#{path}.json"
116
+ elsif File.exists? local_path_to("#{path}.yml")
117
+ local_path_to "#{path}.yml"
118
+ elsif File.exists? local_path_to("#{path}.yaml")
119
+ local_path_to "#{path}.yaml"
120
+ elsif File.exists? local_path_to("#{path}.yamldb")
121
+ local_path_to "#{path}.yamldb"
122
+ elsif File.directory? local_path_to(path)
123
+ local_path_to(path)
91
124
  else
92
- raise "No data found for #{path}"
93
- #nil #TODO: Should it die if it can't find data?
125
+ #FIXME: Should it die if it can't find data?\
126
+ # raise "No data found for #{path}"
127
+ Gumdrop.report "No data found for #{path}", :warning
128
+ nil
94
129
  end
95
130
  end
131
+
132
+ def local_path_to(filename)
133
+ File.join(@dir.to_s, filename.to_s)
134
+ end
96
135
  end
97
136
  end