rticles 0.1.0

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 (77) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +19 -0
  5. data/LICENSE.txt +661 -0
  6. data/README.md +52 -0
  7. data/Rakefile +30 -0
  8. data/lib/rticles.rb +8 -0
  9. data/lib/rticles/document.rb +200 -0
  10. data/lib/rticles/generators/install_generator.rb +18 -0
  11. data/lib/rticles/generators/templates/create_documents_and_paragraphs.rb +24 -0
  12. data/lib/rticles/numbering.rb +56 -0
  13. data/lib/rticles/paragraph.rb +315 -0
  14. data/lib/rticles/railtie.rb +5 -0
  15. data/lib/rticles/version.rb +3 -0
  16. data/lib/tasks/rticles_tasks.rake +4 -0
  17. data/rticles.gemspec +26 -0
  18. data/spec/document_spec.rb +193 -0
  19. data/spec/dummy/.gitignore +6 -0
  20. data/spec/dummy/.rspec +1 -0
  21. data/spec/dummy/README.rdoc +261 -0
  22. data/spec/dummy/Rakefile +7 -0
  23. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  24. data/spec/dummy/app/assets/javascripts/documents.js +25 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css.sass +30 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  27. data/spec/dummy/app/controllers/documents_controller.rb +51 -0
  28. data/spec/dummy/app/controllers/paragraphs_controller.rb +76 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/helpers/documents_helper.rb +2 -0
  31. data/spec/dummy/app/helpers/paragraphs_helper.rb +2 -0
  32. data/spec/dummy/app/mailers/.gitkeep +0 -0
  33. data/spec/dummy/app/models/.gitkeep +0 -0
  34. data/spec/dummy/app/views/documents/edit.html.haml +16 -0
  35. data/spec/dummy/app/views/documents/index.html.haml +8 -0
  36. data/spec/dummy/app/views/documents/new.html.haml +9 -0
  37. data/spec/dummy/app/views/documents/show.html.haml +7 -0
  38. data/spec/dummy/app/views/layouts/application.html.haml +13 -0
  39. data/spec/dummy/app/views/paragraphs/_form.html.haml +8 -0
  40. data/spec/dummy/app/views/paragraphs/_paragraph.html.haml +21 -0
  41. data/spec/dummy/app/views/paragraphs/_paragraph_internal.html.haml +18 -0
  42. data/spec/dummy/app/views/paragraphs/edit.html.haml +7 -0
  43. data/spec/dummy/app/views/paragraphs/new.html.haml +7 -0
  44. data/spec/dummy/app/views/paragraphs/update.js.erb +1 -0
  45. data/spec/dummy/config.ru +4 -0
  46. data/spec/dummy/config/application.rb +65 -0
  47. data/spec/dummy/config/boot.rb +10 -0
  48. data/spec/dummy/config/database.yml +25 -0
  49. data/spec/dummy/config/environment.rb +5 -0
  50. data/spec/dummy/config/environments/development.rb +37 -0
  51. data/spec/dummy/config/environments/production.rb +67 -0
  52. data/spec/dummy/config/environments/test.rb +37 -0
  53. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/dummy/config/initializers/inflections.rb +15 -0
  55. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  56. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  57. data/spec/dummy/config/initializers/session_store.rb +8 -0
  58. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/spec/dummy/config/locales/en.yml +5 -0
  60. data/spec/dummy/config/routes.rb +14 -0
  61. data/spec/dummy/db/migrate/20120828203449_create_documents_and_paragraphs.rb +24 -0
  62. data/spec/dummy/db/schema.rb +35 -0
  63. data/spec/dummy/lib/assets/.gitkeep +0 -0
  64. data/spec/dummy/log/.gitkeep +0 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +25 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/fixtures/constitution.yml +31 -0
  71. data/spec/fixtures/ips.yml +484 -0
  72. data/spec/fixtures/simple.yml +5 -0
  73. data/spec/paragraph_spec.rb +251 -0
  74. data/spec/spec_helper.rb +38 -0
  75. data/spec/support/custom_matchers.rb +1 -0
  76. data/spec/support/document_macros.rb +30 -0
  77. metadata +220 -0
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_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,25 @@
1
+ $(document).ready(function () {
2
+ $('a.insert_paragraph').click(function (event) {
3
+ event.preventDefault();
4
+ $(event.target).parent('.control').siblings('.insert_paragraph_form').show('fast');
5
+ $(event.target).parent('.control').hide();
6
+ });
7
+
8
+ $('.insert_paragraph_form a.cancel').click(function (event) {
9
+ event.preventDefault();
10
+ $(event.target).parents('.insert_paragraph_form').hide('fast');
11
+ $(event.target).parents('.insert_paragraph_form').siblings('.control').show();
12
+ });
13
+
14
+ $('a.edit_paragraph').on('click', function (event) {
15
+ event.preventDefault();
16
+ $(event.target).closest('.paragraph_wrapper').hide();
17
+ $(event.target).closest('.paragraph_internal').children('.edit_paragraph_form').show('fast');
18
+ });
19
+
20
+ $('.edit_paragraph_form a.cancel').on('click', function (event) {
21
+ event.preventDefault();
22
+ $(event.target).closest('.edit_paragraph_form').hide('fast');
23
+ $(event.target).closest('.edit_paragraph_form').siblings('.paragraph_wrapper').show();
24
+ });
25
+ });
@@ -0,0 +1,30 @@
1
+ *, html, body
2
+ :margin 0
3
+ :padding 0
4
+ body
5
+ :padding 1em
6
+ p
7
+ :margin 0 0 1em
8
+ ol
9
+ :list-style-type none
10
+ li
11
+ :margin-left 2em
12
+ &.control
13
+ :margin-top 0.5em
14
+ :margin-bottom 0.5em
15
+ p.control
16
+ :font-family Helvetica, Arial, sans-serif
17
+ :font-size 0.8em
18
+ :color gray
19
+ p.flash
20
+ :color white
21
+ &.notice
22
+ :background-color green
23
+ &.alert
24
+ :background-color red
25
+ li.paragraph
26
+ :border 1px solid gray
27
+ :padding 0.5em
28
+ textarea#paragraph_body
29
+ :width 100%
30
+ :height 4em
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,51 @@
1
+ class DocumentsController < ApplicationController
2
+ def index
3
+ @documents = Rticles::Document.all
4
+ end
5
+
6
+ def new
7
+ @document = Rticles::Document.new
8
+ end
9
+
10
+ def create
11
+ @document = Rticles::Document.new(params[:document])
12
+ if @document.save
13
+ redirect_to document_path(@document), :notice => "New document created."
14
+ else
15
+ flash.now[:alert] = "There was a problem creating your new document."
16
+ render :action => 'new'
17
+ end
18
+ end
19
+
20
+ def show
21
+ @document = Rticles::Document.find(params[:id])
22
+
23
+ if params[:choices]
24
+ choices = {}
25
+ params[:choices].each do |k, v|
26
+ choices[k] = (v == 'true' ? true : false)
27
+ end
28
+ @document.choices = choices
29
+ end
30
+
31
+ if params[:insertions]
32
+ @document.insertions = params[:insertions]
33
+ end
34
+
35
+ # Some non-standard numbering set-up, for demonstration
36
+ @document.numbering_config.innermost_only = true
37
+
38
+ @document.numbering_config[1].format = '#.'
39
+
40
+ @document.numbering_config[2].style = Rticles::Numbering::LOWER_ALPHA
41
+ @document.numbering_config[2].format = '(#)'
42
+
43
+ @document.numbering_config[3].style = Rticles::Numbering::LOWER_ROMAN
44
+ @document.numbering_config[3].format = '(#)'
45
+ end
46
+
47
+ def edit
48
+ @document = Rticles::Document.find(params[:id])
49
+ @editing = true
50
+ end
51
+ end
@@ -0,0 +1,76 @@
1
+ class ParagraphsController < ApplicationController
2
+ before_filter :find_document
3
+ before_filter :find_paragraph, :only => [:edit, :update, :destroy, :indent, :outdent, :move_higher, :move_lower]
4
+
5
+ def index
6
+ redirect_to document_path(@document)
7
+ end
8
+
9
+ def new
10
+ @paragraph = @document.paragraphs.build
11
+
12
+ @paragraph.before_id = params[:before_id] if params[:before_id]
13
+ @paragraph.after_id = params[:after_id] if params[:after_id]
14
+ end
15
+
16
+ def create
17
+ @paragraph = @document.paragraphs.build(params[:paragraph])
18
+ if @paragraph.save
19
+ redirect_to document_path(@document, :anchor => dom_id(@paragraph)), :notice => "Paragraph added."
20
+ else
21
+ flash.now[:alert] = "There was a problem saving the new paragraph."
22
+ render :action => :new
23
+ end
24
+ end
25
+
26
+ def edit
27
+ @paragraph.prepare_for_editing
28
+ end
29
+
30
+ def update
31
+ if @paragraph.update_attributes(params[:paragraph])
32
+ respond_to do |format|
33
+ format.html {redirect_to document_path(@document, :anchor => dom_id(@paragraph)), :notice => "Paragraph updated."}
34
+ format.js
35
+ end
36
+ else
37
+ flash.now[:alert] = "There was a problem updating the paragraph."
38
+ render :action => :edit
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ @paragraph.destroy
44
+ redirect_to document_path(@document), :notice => "Paragraph deleted."
45
+ end
46
+
47
+ def indent
48
+ @paragraph.indent!
49
+ redirect_to document_path(@document, :anchor => dom_id(@paragraph))
50
+ end
51
+
52
+ def outdent
53
+ @paragraph.outdent!
54
+ redirect_to document_path(@document, :anchor => dom_id(@paragraph))
55
+ end
56
+
57
+ def move_lower
58
+ @paragraph.move_lower
59
+ redirect_to document_path(@document, :anchor => dom_id(@paragraph))
60
+ end
61
+
62
+ def move_higher
63
+ @paragraph.move_higher
64
+ redirect_to document_path(@document, :anchor => dom_id(@paragraph))
65
+ end
66
+
67
+ private
68
+
69
+ def find_document
70
+ @document = Rticles::Document.find(params[:document_id])
71
+ end
72
+
73
+ def find_paragraph
74
+ @paragraph = @document.paragraphs.find(params[:id])
75
+ end
76
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module DocumentsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ParagraphsHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,16 @@
1
+ %h1= @document.title
2
+ %ol
3
+ - @document.top_level_paragraphs.each do |paragraph|
4
+ = render :partial => 'paragraphs/paragraph', :object => paragraph
5
+
6
+ - if @document.top_level_paragraphs.empty?
7
+ .insert_paragraph_wrapper
8
+ %p.control
9
+ = link_to "Insert paragraph", new_document_paragraph_path(:document_id => @document), :class => 'insert_paragraph'
10
+ .insert_paragraph_form{:style => "display: none;"}
11
+ = form_for :paragraph, :url => document_paragraphs_path(:document_id => @document) do |f|
12
+ = render(:partial => 'paragraphs/form', :locals => {:f => f, :cancel_link => true})
13
+
14
+
15
+ %p
16
+ = link_to "Back to documents list.", documents_path
@@ -0,0 +1,8 @@
1
+ %h1 Documents
2
+ %ul
3
+ - @documents.each do |document|
4
+ %li
5
+ = link_to document.title, document_path(document)
6
+ = link_to "Edit", edit_document_path(document)
7
+ %p
8
+ = link_to "New document.", new_document_path
@@ -0,0 +1,9 @@
1
+ %h1 New document
2
+ = form_for @document, :url => documents_path do |f|
3
+ %p
4
+ = f.label :title
5
+ = f.text_field :title
6
+ %p
7
+ = f.submit "Create"
8
+ %p
9
+ = link_to "Cancel and go back.", documents_path
@@ -0,0 +1,7 @@
1
+ %h1= @document.title
2
+
3
+ = @document.to_html
4
+
5
+ %p
6
+ = link_to "Edit this document", edit_document_path(:id => @document)
7
+ = link_to "Back to documents list.", documents_path
@@ -0,0 +1,13 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
5
+ %title Rticles
6
+ = javascript_include_tag 'application'
7
+ = stylesheet_link_tag 'application'
8
+ %body
9
+ - if flash[:alert]
10
+ %p.flash.alert= flash[:alert]
11
+ - if flash[:notice]
12
+ %p.flash.notice= flash[:notice]
13
+ = yield
@@ -0,0 +1,8 @@
1
+ %p
2
+ = f.text_area :body
3
+ = f.hidden_field :before_id
4
+ = f.hidden_field :after_id
5
+ %p
6
+ = f.submit "Save"
7
+ - if defined?(cancel_link)
8
+ = link_to("Cancel", documents_path, :class => 'cancel')
@@ -0,0 +1,21 @@
1
+ - if @editing
2
+ %li.control
3
+ %p.control
4
+ = link_to "Insert paragraph", new_document_paragraph_path(:document_id => paragraph.document, :before_id => paragraph.id), :class => 'insert_paragraph'
5
+ .insert_paragraph_form{:style => "display: none;"}
6
+ = form_for Rticles::Paragraph.new(:before_id => paragraph.id), :as => :paragraph, :url => document_paragraphs_path(:document_id => paragraph.document) do |f|
7
+ = render(:partial => 'paragraphs/form', :locals => {:f => f, :cancel_link => true})
8
+ = content_tag_for(:li, paragraph) do
9
+ = render(:partial => 'paragraphs/paragraph_internal', :locals => {:paragraph => paragraph})
10
+ - unless paragraph.children.empty?
11
+ %ol
12
+ - paragraph.children.each do |sub_paragraph|
13
+ = render :partial => 'paragraphs/paragraph', :object => sub_paragraph
14
+ - if @editing
15
+ - if paragraph.last?
16
+ %li.control
17
+ %p.control
18
+ = link_to "Insert paragraph", new_document_paragraph_path(:document_id => paragraph.document, :after_id => paragraph.id), :class => 'insert_paragraph'
19
+ .insert_paragraph_form{:style => "display: none;"}
20
+ = form_for Rticles::Paragraph.new(:after_id => paragraph.id), :as => :paragraph, :url => document_paragraphs_path(:document_id => paragraph.document) do |f|
21
+ = render(:partial => 'paragraphs/form', :locals => {:f => f, :cancel_link => true})
@@ -0,0 +1,18 @@
1
+ .paragraph_internal
2
+ .paragraph_wrapper
3
+ - if paragraph.heading?
4
+ = content_tag("h#{paragraph.heading_level}") do
5
+ = paragraph.body_for_display
6
+ - else
7
+ = simple_format(paragraph.full_index + ' ' + paragraph.body_for_display)
8
+ - if @editing
9
+ %p.control
10
+ = link_to "Edit", edit_document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :class => 'edit_paragraph'
11
+ = link_to_if paragraph.can_move_higher?, "Move up", move_higher_document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :method => :post
12
+ = link_to_if paragraph.can_move_lower?, "Move down", move_lower_document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :method => :post
13
+ = link_to_if paragraph.can_outdent?, "Outdent", outdent_document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :method => :post
14
+ = link_to_if paragraph.can_indent?, "Indent", indent_document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :method => :post
15
+ = link_to "Delete", document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :method => :delete
16
+ .edit_paragraph_form{:style => "display: none;"}
17
+ = form_for paragraph.prepare_for_editing, :as => :paragraph, :url => document_paragraph_path(:document_id => paragraph.document, :id => paragraph), :method => :put, :remote => true do |f|
18
+ = render(:partial => 'paragraphs/form', :locals => {:f => f, :cancel_link => true})
@@ -0,0 +1,7 @@
1
+ %h1 Edit paragraph
2
+ %p
3
+ To insert a reference, add an exclamation mark before the paragraph number: !4.2
4
+ = form_for [@document, @paragraph] do |f|
5
+ = render :partial => 'form', :locals => {:f => f}
6
+ %p
7
+ = link_to "Cancel and go back.", document_path(@document)
@@ -0,0 +1,7 @@
1
+ %h1 New paragraph
2
+ %p
3
+ To insert a reference, add an exclamation mark before the paragraph number: !4.2
4
+ = form_for [@document, @paragraph] do |f|
5
+ = render :partial => 'form', :locals => {:f => f}
6
+ %p
7
+ = link_to "Cancel and go back.", document_path(@document)
@@ -0,0 +1 @@
1
+ $('#<%=j dom_id(@paragraph) %> .paragraph_internal').replaceWith("<%=j render :partial => 'paragraphs/paragraph_internal', :locals => {:paragraph => @paragraph} %>");
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "active_resource/railtie"
8
+ require "sprockets/railtie"
9
+ # require "rails/test_unit/railtie"
10
+
11
+ Bundler.require
12
+ require "rticles"
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Custom directories with classes and modules you want to be autoloadable.
21
+ # config.autoload_paths += %W(#{config.root}/extras)
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named.
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Activate observers that should always be running.
28
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
29
+
30
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
31
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
32
+ # config.time_zone = 'Central Time (US & Canada)'
33
+
34
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
35
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
36
+ # config.i18n.default_locale = :de
37
+
38
+ # Configure the default encoding used in templates for Ruby 1.9.
39
+ config.encoding = "utf-8"
40
+
41
+ # Configure sensitive parameters which will be filtered from the log file.
42
+ config.filter_parameters += [:password]
43
+
44
+ # Enable escaping HTML in JSON.
45
+ config.active_support.escape_html_entities_in_json = true
46
+
47
+ # Use SQL instead of Active Record's schema dumper when creating the database.
48
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
49
+ # like if you have constraints or database-specific column types
50
+ # config.active_record.schema_format = :sql
51
+
52
+ # Enforce whitelist mode for mass assignment.
53
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
54
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
55
+ # parameters by using an attr_accessible or attr_protected declaration.
56
+ config.active_record.whitelist_attributes = true
57
+
58
+ # Enable the asset pipeline
59
+ config.assets.enabled = true
60
+
61
+ # Version of your assets, change this if you want to expire all your assets
62
+ config.assets.version = '1.0'
63
+ end
64
+ end
65
+