birdses 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +49 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/javascripts/birdses/application.js +15 -0
  5. data/app/assets/javascripts/birdses/pages.js +44 -0
  6. data/app/assets/stylesheets/birdses/application.css +13 -0
  7. data/app/assets/stylesheets/birdses/pages.css +23 -0
  8. data/app/controllers/birdses/application_controller.rb +2 -0
  9. data/app/controllers/birdses/pages_controller.rb +61 -0
  10. data/app/helpers/birdses/application_helper.rb +4 -0
  11. data/app/helpers/birdses/pages_helper.rb +41 -0
  12. data/app/models/birdses/page.rb +54 -0
  13. data/app/views/birdses/pages/_editor.html.erb +22 -0
  14. data/app/views/birdses/pages/_nav.html.erb +24 -0
  15. data/app/views/birdses/pages/edit.html.erb +2 -0
  16. data/app/views/birdses/pages/index.html.erb +10 -0
  17. data/app/views/birdses/pages/new.html.erb +2 -0
  18. data/app/views/birdses/pages/preview.js.erb +1 -0
  19. data/app/views/birdses/pages/show.html.erb +3 -0
  20. data/config/routes.rb +6 -0
  21. data/lib/birdses.rb +4 -0
  22. data/lib/birdses/engine.rb +8 -0
  23. data/lib/birdses/version.rb +3 -0
  24. data/lib/tasks/birdses_tasks.rake +4 -0
  25. data/spec/dummy/README.rdoc +1 -0
  26. data/spec/dummy/Rakefile +7 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/spec/dummy/config.ru +4 -0
  33. data/spec/dummy/config/application.rb +65 -0
  34. data/spec/dummy/config/boot.rb +10 -0
  35. data/spec/dummy/config/environment.rb +5 -0
  36. data/spec/dummy/config/environments/development.rb +31 -0
  37. data/spec/dummy/config/environments/production.rb +64 -0
  38. data/spec/dummy/config/environments/test.rb +35 -0
  39. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  40. data/spec/dummy/config/initializers/inflections.rb +15 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  43. data/spec/dummy/config/initializers/session_store.rb +8 -0
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +10 -0
  45. data/spec/dummy/config/locales/en.yml +5 -0
  46. data/spec/dummy/config/routes.rb +4 -0
  47. data/spec/dummy/log/development.log +25925 -0
  48. data/spec/dummy/public/404.html +26 -0
  49. data/spec/dummy/public/422.html +26 -0
  50. data/spec/dummy/public/500.html +25 -0
  51. data/spec/dummy/public/favicon.ico +0 -0
  52. data/spec/dummy/script/rails +6 -0
  53. data/spec/dummy/tmp/cache/assets/C79/4D0/sprockets%2Ff8925d25130e89f28ac1c9812d300124 +0 -0
  54. data/spec/dummy/tmp/cache/assets/CA9/D50/sprockets%2F009bef11fd535858e6a67981110006bd +0 -0
  55. data/spec/dummy/tmp/cache/assets/CCA/B20/sprockets%2F1429cedc011a7804c073262337d17cdb +0 -0
  56. data/spec/dummy/tmp/cache/assets/CD0/550/sprockets%2F0dcdb518b4dbd350e006576671c67330 +0 -0
  57. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  58. data/spec/dummy/tmp/cache/assets/CE8/820/sprockets%2F01dea23bd99895247c856db1d89342b4 +0 -0
  59. data/spec/dummy/tmp/cache/assets/CFB/4E0/sprockets%2Fad6f00c8038e012ead1942060c7b0f68 +0 -0
  60. data/spec/dummy/tmp/cache/assets/D00/C10/sprockets%2F96d2f16181ed18060d311b308ed8acd1 +0 -0
  61. data/spec/dummy/tmp/cache/assets/D1E/7A0/sprockets%2F73cc9ff9f752d51fe185cf9581146a10 +0 -0
  62. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  63. data/spec/dummy/tmp/cache/assets/D4B/990/sprockets%2F5239d66258d289c87cc5aa0c74da5ec7 +0 -0
  64. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  65. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  66. data/spec/dummy/tmp/cache/assets/D69/390/sprockets%2F3bb3c7a783bcf4d2022b947ce63074fe +0 -0
  67. data/spec/dummy/tmp/cache/assets/D7A/620/sprockets%2Fffc3dde2418abf58d9d904f22e187814 +0 -0
  68. data/spec/dummy/tmp/cache/assets/D9A/2A0/sprockets%2F24a17d7a6e6cc32a1fd3faa968b80b85 +0 -0
  69. data/spec/dummy/tmp/cache/assets/D9C/ED0/sprockets%2Fbb6bd29a4bab7e880ac48026dd29639b +0 -0
  70. data/spec/dummy/tmp/cache/assets/DB1/460/sprockets%2F2c1065b52ccbc7cc3d062ce034ccd1c7 +0 -0
  71. data/spec/dummy/tmp/cache/assets/DC8/310/sprockets%2Ffdfd001fdc6f28df927027cdac2d9212 +0 -0
  72. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  73. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  74. data/spec/dummy/wiki//"system('echo-$ENV').md +0 -0
  75. data/spec/dummy/wiki/#{`ruby--v`}.md +1 -0
  76. data/spec/dummy/wiki/This-is-amazing.md +21 -0
  77. data/spec/dummy/wiki/This-is-an-amazing-title.md +3 -0
  78. data/spec/dummy/wiki/a.md +1 -0
  79. data/spec/dummy/wiki/amazing.md +28 -0
  80. data/spec/dummy/wiki/daily-standup-meetings.md +5 -0
  81. data/spec/dummy/wiki/hello.md +24 -0
  82. data/spec/dummy/wiki/home.md +1 -0
  83. data/spec/dummy/wiki/internal-webinars.md +11 -0
  84. data/spec/dummy/wiki/test-on-travis-ci.md +39 -0
  85. data/spec/spec_helper.rb +12 -0
  86. metadata +245 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Maximilian Haack
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Birdses
2
+
3
+ Birdses implements views for [gollum](https://github.com/github/gollum) as a mountable rails engine.
4
+
5
+ Add Birdses to your rails application in three easy steps:
6
+
7
+ 1. add `gem 'birdses'` to your Gemfile and run `bundle install`
8
+ 2. add `mount Birdses::Engine => "/wiki"` to your `config/routes.rb`
9
+ 3. init a [git](http://git-scm.com/) repository under `wiki/`
10
+ (you can do this by running `rake init_wiki`)
11
+
12
+ ## Caveats
13
+
14
+ ### `current_user`
15
+
16
+ If you're using an authentication system that provides a `current_user` method (like [devise](https://github.com/plataformatec/devise)), birdses will try to access `.fullname` and `.email` (on `current_user`). It will use these for the commit messages.
17
+
18
+ ### `_url`/`_path`
19
+
20
+ If you use any magic url mappers (any method that ends with `_path` or `_url`) in the application layout you will have to use the `main_app` [helper](http://edgeguides.rubyonrails.org/engines.html#using-a-class-provided-by-the-application).
21
+
22
+ For example, I use [Twitter Bootstrap](http://twitter.github.com/bootstrap/) and have a 'Sign Out' link in my navigation bar. For it to work properly with birdses I have to prepend the helper method.
23
+
24
+ without birdes:
25
+ ```haml
26
+ # ...
27
+ - if current_user
28
+ %li= link_to('Sign Out', destroy_user_session_path, method: :delete)
29
+ # ...
30
+ ```
31
+
32
+ with birdses:
33
+ ```haml
34
+ # ...
35
+ - if current_user
36
+ %li= link_to('Sign Out', main_app.destroy_user_session_path, method: :delete)
37
+ # ...
38
+ ```
39
+
40
+ Otherwise you will get errors like this, when accessing the mounted wiki:
41
+
42
+ ```
43
+ NameError in Birdses/pages#index
44
+
45
+ Showing /Users/max/code/snap_app/app/views/layouts/application.html.haml where line #43 raised:
46
+
47
+ undefined local variable or method `destroy_user_session_path' for
48
+ #<#<Class:0x007fd67c3d6418>:0x007fd67afb3508>
49
+ ```
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Birdses'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec)
25
+
26
+ # RSpec as default
27
+ task :default => :spec
28
+
29
+ desc 'create git repo for the wiki'
30
+ task :init_wiki do
31
+ sh 'mkdir -p spec/dummy/wiki/'
32
+ Dir.chdir('spec/dummy/wiki') do
33
+ sh 'git init && echo "Hi" > home.md && git add . && git commit -m "init"'
34
+ end
35
+ end
36
+
37
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,44 @@
1
+ $(document).ready(function() {
2
+ // Editor
3
+ var textarea = $("[id$=page_raw_data]");
4
+ textarea.hide();
5
+ var editor = ace.edit("editor");
6
+ editor.getSession().setValue(textarea.val());
7
+ editor.setTheme("ace/theme/tomorrow");
8
+ editor.getSession().setMode("ace/mode/markdown");
9
+ editor.getSession().setTabSize(2);
10
+ editor.resize();
11
+ $("#editor_form").submit(function(){
12
+ textarea.val(editor.getSession().getValue());
13
+ });
14
+
15
+ // Preview
16
+ var preview = $('[name$=preview_button]');
17
+ preview.click(function(event) {
18
+ event.preventDefault();
19
+
20
+ // set the page's name to the value of the hidden preview textbox
21
+ $('#preview_name').val(function () {
22
+ var name = $('h2').html();
23
+ if ('New Page' == name) {
24
+ name = $('#page_name').val()
25
+ }
26
+ return name
27
+ });
28
+
29
+ // set the page's content to the value of the hidden content preview box
30
+ $('#preview_content').val(editor.getSession().getValue());
31
+
32
+ // Toggle the title of the Preview Button
33
+ $('#editor').toggle();
34
+ $('#preview').toggle(10, function(){
35
+ if ($('#preview').is(':visible')) {
36
+ preview.val('Edit');
37
+ $('#preview_form').submit();
38
+ } else {
39
+ preview.val('Preview');
40
+ }
41
+ });
42
+ });
43
+ });
44
+
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,23 @@
1
+ #editor {
2
+ position: absolute;
3
+ margin-top: 25px;
4
+ width: 80%;
5
+ height: 80%;
6
+ }
7
+
8
+ #preview {
9
+ margin-top: 25px;
10
+ display: none;
11
+ }
12
+
13
+ #birdses_pages_nav ul {
14
+ margin-left: 0;
15
+ margin-right: 50px;
16
+ margin-bottom: 20px;
17
+ list-style: none;
18
+ float: right;
19
+ }
20
+
21
+ #birdses_pages_nav li {
22
+ display: inline;
23
+ }
@@ -0,0 +1,2 @@
1
+ class Birdses::ApplicationController < ApplicationController
2
+ end
@@ -0,0 +1,61 @@
1
+ require_dependency "birdses/application_controller"
2
+
3
+ module Birdses
4
+ class PagesController < ApplicationController
5
+ before_filter :get_user
6
+
7
+ def index
8
+ @pages = Page.all
9
+ end
10
+
11
+ def new
12
+ @page = Page.new
13
+ end
14
+
15
+ def create
16
+ name = params[:page][:name]
17
+ content = params[:page][:raw_data]
18
+ @page = Page.create(name, content, @user)
19
+ redirect_to "#{pages_path}/#{name.parameterize}"
20
+ end
21
+
22
+ def show
23
+ @page = Page.find_by_name(params[:id])
24
+ end
25
+
26
+ def edit
27
+ @page = Page.find_by_name(params[:id])
28
+ end
29
+
30
+ def update
31
+ name = params[:id]
32
+ content = params[:page][:raw_data]
33
+ Page.update(name, content, @user)
34
+ redirect_to "#{pages_path}/#{name.parameterize}"
35
+ end
36
+
37
+ def destroy
38
+ Page.destroy(params[:id], @user)
39
+ redirect_to pages_path
40
+ end
41
+
42
+ def preview
43
+ preview = Page.preview(params[:name], params[:content])
44
+ @content = preview.formatted_data
45
+ end
46
+
47
+ private
48
+
49
+ def get_user
50
+ name = 'Anonymous'
51
+ email = 'anon@example.com'
52
+ if defined?(current_user)
53
+ # this rescue is necessary because .try?(:method) does not work on
54
+ # `current_user`
55
+ name = current_user.fullname rescue 'Anonymous'
56
+ email = current_user.email rescue 'anon@example.com'
57
+ end
58
+ @user = { 'name' => name, 'email' => email }
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ module Birdses
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ module Birdses
2
+ module PagesHelper
3
+ def index?
4
+ current?(:index) || current_page?(root_url)
5
+ end
6
+
7
+ def new?
8
+ current?(:new)
9
+ end
10
+
11
+ def edit?
12
+ current?(:edit)
13
+ end
14
+
15
+ def create_or_update?
16
+ if new?
17
+ :create
18
+ elsif edit?
19
+ :update
20
+ end
21
+ end
22
+
23
+ def post_or_put?
24
+ if new?
25
+ :post
26
+ elsif edit?
27
+ :put
28
+ end
29
+ end
30
+
31
+ def current?(page)
32
+ current_page?(controller: 'pages', action: page)
33
+ end
34
+
35
+ def title(page)
36
+ doc = Nokogiri::HTML::fragment(page.formatted_data, 'UTF-8')
37
+ h1 = doc.css("h1:first-child")
38
+ raw("<h1>#{page.name}</h1>") if h1.empty?
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,54 @@
1
+ require 'gollum'
2
+
3
+ module Birdses
4
+ module Page
5
+ extend self
6
+ WIKI_FORMAT = :markdown
7
+
8
+ def all
9
+ wiki.pages
10
+ end
11
+
12
+ def new
13
+ Struct.new(:name, :raw_data).new('New Page', '')
14
+ end
15
+
16
+ def create(page_name, content, user)
17
+ wiki.write_page(page_name, WIKI_FORMAT, content,
18
+ build_commit(user, "creating #{page_name}"))
19
+ end
20
+
21
+ def update(page_name, content, user)
22
+ page = find_by_name(page_name)
23
+ wiki.update_page(page, page.name, page.format, content,
24
+ build_commit(user, "updating #{page_name}"))
25
+ end
26
+
27
+ def destroy(page_name, user)
28
+ page = find_by_name(page_name)
29
+ wiki.delete_page(page, build_commit(user, "delete #{page_name}"))
30
+ end
31
+
32
+ def find_by_name(name)
33
+ wiki.page(name)
34
+ end
35
+
36
+ def preview(page_name, content)
37
+ wiki.preview_page(page_name, content, WIKI_FORMAT)
38
+ end
39
+
40
+ private
41
+
42
+ def wiki
43
+ Gollum::Wiki.new(Rails.root.join('wiki'))
44
+ end
45
+
46
+ def build_commit(user, message)
47
+ {
48
+ message: message,
49
+ name: user['name'],
50
+ email: user['email']
51
+ }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ <h2><%= @page.name %></h2>
2
+
3
+ <%= form_for :page, url: { action: create_or_update? },
4
+ method: post_or_put?, html: { id: 'editor_form' } do |f| %>
5
+ <% if new? %>
6
+ <%= f.text_field :name %>
7
+ <% end %>
8
+ <%= f.text_area :raw_data %>
9
+ <%= f.submit %>
10
+ <%= f.submit "Preview", :name => 'preview_button' %>
11
+ <div id="editor"></div>
12
+ <div id="preview"></div>
13
+ <% end %>
14
+
15
+ <%= form_tag "#{pages_path}/doesntmatter/preview", id: 'preview_form',
16
+ remote: true do -%>
17
+ <%= hidden_field_tag 'name', 'title', { id: 'preview_name' } %>
18
+ <%= hidden_field_tag 'content', 'content', { id: 'preview_content' } %>
19
+ <% end %>
20
+
21
+ <%= javascript_include_tag "birdses/application" %>
22
+ <%= javascript_include_tag "http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" %>
@@ -0,0 +1,24 @@
1
+ <%= stylesheet_link_tag "birdses/application", :media => "all" %>
2
+
3
+ <div id='birdses_pages_nav'>
4
+ <ul>
5
+ <% unless index? %>
6
+ <li>
7
+ <%= link_to 'Wiki Home', root_url %>
8
+ </li>
9
+ <% end %>
10
+ <li>
11
+ <%= link_to_unless_current 'New Page', new_page_path %>
12
+ </li>
13
+ <% unless index? || new? || edit? %>
14
+ <li>
15
+ <%= link_to 'Edit', controller: 'pages', action: :edit,
16
+ id: @page.name %>
17
+ </li>
18
+ <li>
19
+ <%= link_to 'Destroy', "#{pages_path}/#{@page.name}", method: :delete,
20
+ confirm: "Are you sure?" %>
21
+ </li>
22
+ <% end %>
23
+ </ul>
24
+ </div>
@@ -0,0 +1,2 @@
1
+ <%= render 'nav' %>
2
+ <%= render 'editor' %>
@@ -0,0 +1,10 @@
1
+ <%= render 'nav' %>
2
+ <h1>Pages</h1>
3
+ <ul>
4
+ <% @pages.each do |page| %>
5
+ <li>
6
+ <%= link_to page.name, controller: 'pages',
7
+ action: :show, id: page.name %>
8
+ </li>
9
+ <% end %>
10
+ </ul>