mongo_fe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +34 -0
  3. data/.rspec +2 -0
  4. data/CHANGES.md +3 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +138 -0
  7. data/LICENSE +22 -0
  8. data/Procfile +2 -0
  9. data/README.md +72 -0
  10. data/Rakefile +14 -0
  11. data/TODO.tasks +9 -0
  12. data/bin/config.ru +28 -0
  13. data/bin/mongofe +54 -0
  14. data/lib/mongo_fe/application_controller.rb +91 -0
  15. data/lib/mongo_fe/controllers/collections_controller.rb +278 -0
  16. data/lib/mongo_fe/controllers/databases_controller.rb +94 -0
  17. data/lib/mongo_fe/helpers/helpers.rb +128 -0
  18. data/lib/mongo_fe/public/app/application.js +3 -0
  19. data/lib/mongo_fe/public/bootstrap/css/bootstrap-responsive.css +567 -0
  20. data/lib/mongo_fe/public/bootstrap/css/bootstrap.css +3380 -0
  21. data/lib/mongo_fe/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
  22. data/lib/mongo_fe/public/bootstrap/img/glyphicons-halflings.png +0 -0
  23. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-alert.js +91 -0
  24. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-button.js +98 -0
  25. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-carousel.js +154 -0
  26. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-collapse.js +136 -0
  27. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-dropdown.js +92 -0
  28. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-modal.js +209 -0
  29. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-popover.js +95 -0
  30. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-scrollspy.js +125 -0
  31. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-tab.js +130 -0
  32. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-tooltip.js +270 -0
  33. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-transition.js +51 -0
  34. data/lib/mongo_fe/public/bootstrap/js/basic/bootstrap-typeahead.js +271 -0
  35. data/lib/mongo_fe/public/bootstrap/js/bootstrap.js +1722 -0
  36. data/lib/mongo_fe/public/bootstrap/js/bootstrap.min.js +1 -0
  37. data/lib/mongo_fe/public/bootstrap/js/jquery.js +9252 -0
  38. data/lib/mongo_fe/public/bootstrap/js/underscore-min.js +32 -0
  39. data/lib/mongo_fe/public/bootstrap/js/underscore.js +1059 -0
  40. data/lib/mongo_fe/public/css/digg_pagination.css +28 -0
  41. data/lib/mongo_fe/public/css/jsoneditor.css +70 -0
  42. data/lib/mongo_fe/public/css/styles.css +11 -0
  43. data/lib/mongo_fe/public/images/missing_avatar_small.png +0 -0
  44. data/lib/mongo_fe/public/js/collection-tools.js +63 -0
  45. data/lib/mongo_fe/public/js/db-tools.js +45 -0
  46. data/lib/mongo_fe/public/js/jsoneditor/jquery.jsoneditor.min.LICENSE +20 -0
  47. data/lib/mongo_fe/public/js/jsoneditor/jquery.jsoneditor.min.js +6 -0
  48. data/lib/mongo_fe/public/js/jsoneditor/json2.js +482 -0
  49. data/lib/mongo_fe/version.rb +6 -0
  50. data/lib/mongo_fe/views/collections/_document_attributes.haml +6 -0
  51. data/lib/mongo_fe/views/collections/_documents.haml +35 -0
  52. data/lib/mongo_fe/views/collections/_documents_page.haml +82 -0
  53. data/lib/mongo_fe/views/collections/_indexes.haml +76 -0
  54. data/lib/mongo_fe/views/collections/index.haml +80 -0
  55. data/lib/mongo_fe/views/databases/_list_users.haml +27 -0
  56. data/lib/mongo_fe/views/databases/info.haml +80 -0
  57. data/lib/mongo_fe/views/footer.haml +4 -0
  58. data/lib/mongo_fe/views/index.haml +7 -0
  59. data/lib/mongo_fe/views/layout.haml +148 -0
  60. data/lib/mongo_fe/views/navbar.haml +17 -0
  61. data/lib/mongo_fe.rb +170 -0
  62. data/mongo_fe.gemspec +50 -0
  63. data/screens/example_db_view.png +0 -0
  64. data/screens/example_doc_view.png +0 -0
  65. data/screens/example_indexes.png +0 -0
  66. data/spec/config_spec.rb +17 -0
  67. data/spec/controllers/collections_controller_spec.rb +151 -0
  68. data/spec/controllers/db_controller_spec.rb +69 -0
  69. data/spec/factories/factories.rb +19 -0
  70. data/spec/spec_helper.rb +88 -0
  71. metadata +559 -0
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore all logfiles and tempfiles.
11
+ /log/*.log
12
+ /tmp
13
+
14
+ .idea/*
15
+ /coverage
16
+ *.gem
17
+ *.rbc
18
+ .bundle
19
+ .config
20
+ coverage
21
+ InstalledFiles
22
+ lib/bundler/man
23
+ pkg
24
+ rdoc
25
+ spec/reports
26
+ test/tmp
27
+ test/version_tmp
28
+ tmp
29
+ .DS_Store
30
+
31
+ # YARD artifacts
32
+ .yardoc
33
+ _yardoc
34
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (2012-07-16)
2
+
3
+ * Initial Release, code name: Simona
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,138 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongo_fe (0.1.0)
5
+ bson
6
+ bson_ext
7
+ chronic (~> 0.6.7)
8
+ coderay (~> 1.0.5)
9
+ haml (~> 3.1.4)
10
+ hashie
11
+ json
12
+ mongo (~> 1.6.2)
13
+ redcarpet (~> 2.1.0)
14
+ sinatra (~> 1.3.2)
15
+ sinatra-contrib (~> 1.3.1)
16
+ tilt (~> 1.3.0)
17
+ vegas (~> 0.1.11)
18
+ will_paginate (>= 3.0.0)
19
+ will_paginate-bootstrap
20
+ yajl-ruby
21
+
22
+ GEM
23
+ remote: http://rubygems.org/
24
+ specs:
25
+ activesupport (3.2.6)
26
+ i18n (~> 0.6)
27
+ multi_json (~> 1.0)
28
+ addressable (2.2.8)
29
+ appraisal (0.4.1)
30
+ bundler
31
+ rake
32
+ backports (2.6.1)
33
+ bson (1.6.4)
34
+ bson_ext (1.6.4)
35
+ bson (~> 1.6.4)
36
+ builder (3.0.0)
37
+ capybara (1.1.2)
38
+ mime-types (>= 1.16)
39
+ nokogiri (>= 1.3.3)
40
+ rack (>= 1.0.0)
41
+ rack-test (>= 0.5.4)
42
+ selenium-webdriver (~> 2.0)
43
+ xpath (~> 0.1.4)
44
+ childprocess (0.3.3)
45
+ ffi (~> 1.0.6)
46
+ chronic (0.6.7)
47
+ coderay (1.0.7)
48
+ cucumber (1.2.1)
49
+ builder (>= 2.1.2)
50
+ diff-lcs (>= 1.1.3)
51
+ gherkin (~> 2.11.0)
52
+ json (>= 1.4.6)
53
+ diff-lcs (1.1.3)
54
+ eventmachine (0.12.10)
55
+ factory_girl (3.5.0)
56
+ activesupport (>= 3.0.0)
57
+ ffi (1.0.11)
58
+ gherkin (2.11.1)
59
+ json (>= 1.4.6)
60
+ haml (3.1.6)
61
+ hashie (1.2.0)
62
+ i18n (0.6.0)
63
+ json (1.7.3)
64
+ libwebsocket (0.1.3)
65
+ addressable
66
+ logger (1.2.8)
67
+ mime-types (1.19)
68
+ mongo (1.6.4)
69
+ bson (~> 1.6.4)
70
+ multi_json (1.3.6)
71
+ nokogiri (1.5.5)
72
+ rack (1.4.1)
73
+ rack-protection (1.2.0)
74
+ rack
75
+ rack-test (0.6.1)
76
+ rack (>= 1.0)
77
+ rake (0.9.2.2)
78
+ redcarpet (2.1.1)
79
+ rspec (2.9.0)
80
+ rspec-core (~> 2.9.0)
81
+ rspec-expectations (~> 2.9.0)
82
+ rspec-mocks (~> 2.9.0)
83
+ rspec-core (2.9.0)
84
+ rspec-expectations (2.9.1)
85
+ diff-lcs (~> 1.1.3)
86
+ rspec-mocks (2.9.0)
87
+ rubyzip (0.9.9)
88
+ selenium-webdriver (2.24.0)
89
+ childprocess (>= 0.2.5)
90
+ libwebsocket (~> 0.1.3)
91
+ multi_json (~> 1.0)
92
+ rubyzip
93
+ shoulda-matchers (1.1.0)
94
+ activesupport (>= 3.0.0)
95
+ simplecov (0.6.4)
96
+ multi_json (~> 1.0)
97
+ simplecov-html (~> 0.5.3)
98
+ simplecov-html (0.5.3)
99
+ sinatra (1.3.2)
100
+ rack (~> 1.3, >= 1.3.6)
101
+ rack-protection (~> 1.2)
102
+ tilt (~> 1.3, >= 1.3.3)
103
+ sinatra-contrib (1.3.1)
104
+ backports (>= 2.0)
105
+ eventmachine
106
+ rack-protection
107
+ rack-test
108
+ sinatra (~> 1.3.0)
109
+ tilt (~> 1.3)
110
+ tilt (1.3.3)
111
+ vegas (0.1.11)
112
+ rack (>= 1.0.0)
113
+ webrat (0.7.3)
114
+ nokogiri (>= 1.2.0)
115
+ rack (>= 1.0)
116
+ rack-test (>= 0.5.3)
117
+ will_paginate (3.0.3)
118
+ will_paginate-bootstrap (0.2.1)
119
+ will_paginate (>= 3.0.3)
120
+ xpath (0.1.4)
121
+ nokogiri (~> 1.3)
122
+ yajl-ruby (1.1.0)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ appraisal (~> 0.4.1)
129
+ bundler (~> 1.1.0)
130
+ capybara (~> 1.1.2)
131
+ cucumber
132
+ factory_girl (~> 3.0)
133
+ logger
134
+ mongo_fe!
135
+ rspec (~> 2.9.0)
136
+ shoulda-matchers (~> 1.1.0)
137
+ simplecov (>= 0.4.2)
138
+ webrat (~> 0.7.3)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Florin T.PĂTRAŞCU
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Procfile ADDED
@@ -0,0 +1,2 @@
1
+ # if you're using homebrew
2
+ mongodb: mongod run --rest --config /usr/local/Cellar/mongodb/2.0.6-x86_64/mongod.conf
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # MongoFe
2
+
3
+ This is a simple Sinatra based web front-end that can be used for experimenting and learning MongoDB. The MongoFe gem can also be used for simple administrative tasks, managing collections and document basic operations such as: create new documents, delete existing ones, search by various criteria and document indexing.
4
+
5
+ ## Installation
6
+
7
+ $ gem install mongo_fe
8
+
9
+ ## Credentials
10
+
11
+ Create a file in your home directory called: `.mongo_fe`
12
+
13
+ In this file add the following:
14
+
15
+ uri: mongodb://localhost:27017
16
+
17
+ Examples:
18
+
19
+ uri: mongodb://nemo:clownfish@ds02231897.mongolab.com:33897/Reef
20
+
21
+ ## Usage
22
+
23
+ Verify first that you have access to a MongoDB instance. [See the install guides](http://www.mongodb.org/display/DOCS/Quickstart/), if need be. I used the [Homebrew](http://mxcl.github.com/homebrew/) package manager to install mongodb. If you have Homebrew, run the following commands:
24
+
25
+ $ brew update
26
+ $ brew install mongodb
27
+
28
+ To start the MongoFe web server:
29
+
30
+ $ mongofe
31
+
32
+ or you can start the web server pointing it to a remote MongoDB url, example:
33
+
34
+ $ mongofe -C mongodb://sheppard:arterius@masseffect3.mongolab.com:33897/datamelee
35
+ $ mongofe -C mongodb://Genetically:Enhanced@"spiritual_successor.mongohq.com:10075/BioShock
36
+
37
+ (fictive links, real syntax)
38
+
39
+ MongoFe works well with remote MongoDB instances, see: [mongolab.com](https://mongolab.com/home) or [mongohq.com](https://mongohq.com), for example.
40
+
41
+ To stop the server:
42
+
43
+ $ mongofe -K
44
+
45
+ ## Screenshots
46
+
47
+ In the mean time, I'd love for you to check out these screenshots to get a feel for MongoFe and see some of the administrative interfaces designed to make your day to day tasks easier.
48
+
49
+ **database info**
50
+ ![Database info](https://img.skitch.com/20120716-g4cbs3yrrwifa5pscnafitw3hw.png)
51
+
52
+ **documents query and management**
53
+ ![Documents view](https://img.skitch.com/20120716-nhjfsadxug7shnkfqmui5wc7qp.png)
54
+
55
+ **index management**
56
+ ![Indexes view](https://img.skitch.com/20120716-c7bwmw31wr3kmsb9ebsufhsrtj.png)
57
+
58
+ Have fun!
59
+
60
+
61
+ ## Contributing
62
+
63
+ * Fork it
64
+ * Create your feature branch (``git checkout -b my-new-feature``)
65
+ * Add some tests and please make sure they pass
66
+ * Commit your changes (``git commit -am 'Added some feature'``)
67
+ * Push to the branch (``git push origin my-new-feature``)
68
+ * Create new Pull Request
69
+
70
+ ## License
71
+ MIT License
72
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ desc 'Default: run tests.'
8
+ task :default => [:spec]
9
+
10
+ task :spec do
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.pattern = './spec/**/*_spec.rb'
13
+ end
14
+ end
data/TODO.tasks ADDED
@@ -0,0 +1,9 @@
1
+ The following describes and discusses a set of functions to be added in the next releases
2
+
3
+ - improve the connection implementation
4
+ - enable the Javascript JSON editor; it is loaded but dormant right now
5
+ - add support for importing/exporting documents
6
+ - add support for geospatial indexes
7
+ - finalize and deploy the 'Collection::Tools' TAB, a set of useful MongoDB commands such as: find/replace/reindex/etc.
8
+ - add support for saving and restoring user preferences, including query objects
9
+ ✓ make this list ;)
data/bin/config.ru ADDED
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'bundler'
4
+ require "hashie/mash"
5
+ require 'cgi'
6
+ require "yaml"
7
+ require 'sinatra/base'
8
+ require 'mongo'
9
+ require 'mongo_fe'
10
+
11
+ begin
12
+ config = Hashie::Mash.new (YAML.load(File.new(File.expand_path('~/.mongo_fe')))) || 'localhost:27017'
13
+ MongoFe::MongoDB.uri = config.uri
14
+ rescue
15
+ $stderr.print "You must create a file in your home directory called .mongo_fe; error: #{$!.message}"
16
+ exit 1
17
+ end
18
+
19
+ # Encoding.default_internal = 'utf-8'
20
+ # Encoding.default_external = 'utf-8'
21
+
22
+ Dir.glob('../lib/{mongo_fe,mongo_fe/helpers,mongo_fe/controllers}/*.rb').each { |file| require file }
23
+
24
+ use MongoFe::ApplicationController
25
+ use MongoFe::DatabasesController
26
+ use MongoFe::CollectionsController
27
+
28
+ run Sinatra::Base
data/bin/mongofe ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require "hashie/mash"
6
+ require 'cgi'
7
+ require "yaml"
8
+ require 'sinatra/base'
9
+ require 'sinatra/contrib'
10
+ require 'mongo'
11
+ require 'mongo_fe'
12
+ require 'vegas'
13
+ require "uri"
14
+
15
+ require "mongo_fe/application_controller"
16
+ require "mongo_fe/controllers/databases_controller"
17
+ require "mongo_fe/controllers/collections_controller"
18
+ require "mongo_fe/helpers/helpers"
19
+
20
+ begin
21
+ config = Hashie::Mash.new (YAML.load(File.new(File.expand_path('~/.mongo_fe')))) || 'mongodb://localhost:27017'
22
+ MongoFe::MongoDB.uri = config.uri
23
+ rescue
24
+ $stderr.puts "You must create a file in your home directory called .mongo_fe; error: #{$!.message}"
25
+ exit 1
26
+ end
27
+
28
+ app = Rack::Builder.new do
29
+ # Dir.glob('../lib/{mongo_fe,mongo_fe/helpers,mongo_fe/controllers}/*.rb').each { |file| require file }
30
+
31
+ begin
32
+ use MongoFe::ApplicationController
33
+ use MongoFe::DatabasesController
34
+ use MongoFe::CollectionsController
35
+
36
+ run Sinatra::Base
37
+ rescue => e
38
+ $stderr.puts "Cannot load the app; error: #{$!.message}"
39
+ exit 1
40
+ end
41
+
42
+ end
43
+
44
+ Vegas::Runner.new( app, 'mongofe', {
45
+ :before_run => lambda { |v|
46
+ path = (ENV['MONGO_FE_CONFIG'] || v.args.first)
47
+ load path.to_s.strip if path
48
+ }
49
+ }) do |runner, opts, app|
50
+
51
+ opts.on('-C uri', "--connect uri", "set the MongodDB connection string") { |uri|
52
+ MongoFe::MongoDB.uri = uri
53
+ }
54
+ end
@@ -0,0 +1,91 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/namespace'
3
+ require "mongo"
4
+ require 'haml'
5
+ require 'chronic'
6
+ require 'will_paginate'
7
+ require 'will_paginate/array'
8
+ require 'will_paginate/view_helpers/sinatra'
9
+ require 'will_paginate/view_helpers/link_renderer'
10
+
11
+ require 'redcarpet'
12
+
13
+ # require "mongo_fe/helpers/helpers"
14
+
15
+ require File.dirname(__FILE__) + '/helpers/helpers'
16
+
17
+ if defined? Encoding
18
+ Encoding.default_external = Encoding::UTF_8
19
+ end
20
+
21
+ module MongoFe
22
+ class ApplicationController < Sinatra::Base
23
+ use Rack::MethodOverride
24
+ register Sinatra::Namespace
25
+ register WillPaginate::Sinatra
26
+
27
+ helpers do
28
+ helpers Helpers
29
+ end
30
+
31
+ dbs = Hashie::Mash.new
32
+
33
+ configure do
34
+ enable :logging
35
+ enable :sessions
36
+ end
37
+
38
+ dir = File.dirname(File.expand_path(__FILE__))
39
+ set :views, "#{dir}/views"
40
+
41
+ if respond_to? :public_folder
42
+ set :public_folder, "#{dir}/public"
43
+ else
44
+ set :public, "#{dir}/public"
45
+ end
46
+
47
+ set :static, true
48
+ set :haml, { :format => :html5 }
49
+ set :session_secret, "something_good" # must have if using shotgun during the development!
50
+
51
+ get '/' do
52
+ begin
53
+ if current_db?
54
+ redirect "/databases/#{current_db_name}"
55
+ else
56
+ haml :index
57
+ end
58
+ rescue =>e
59
+ e.message
60
+ end
61
+ end
62
+
63
+ not_found do
64
+ %Q(Sorry this page doesn't exist)
65
+ end
66
+
67
+ end
68
+
69
+ class MarkdownRenderer < Redcarpet::Render::HTML
70
+ include Redcarpet::Render::SmartyPants
71
+
72
+ def block_code(code, language)
73
+ CodeRay.highlight(code, language)
74
+ end
75
+
76
+ def escape_html(html)
77
+ Rack::Utils.escape_html(html)
78
+ end
79
+ end
80
+
81
+ # teach HAML how to use RedCarpet for markdown docs
82
+ module Haml::Filters::Redcarpet
83
+ include Haml::Filters::Base
84
+
85
+ def render(text)
86
+ Redcarpet::Markdown.new( MongoFe::MarkdownRenderer,
87
+ :autolink => true, :space_after_headers => true, :fenced_code_blocks => true).
88
+ render(text)
89
+ end
90
+ end
91
+ end