appdoc 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/app/controllers/documents_controller.rb +72 -0
- data/app/models/document.rb +32 -0
- data/app/views/documents/_documents.html.haml +18 -0
- data/app/views/documents/_form.html.haml +31 -0
- data/app/views/documents/_index_aside.html.haml +5 -0
- data/app/views/documents/edit.html.haml +2 -0
- data/app/views/documents/index.html.haml +12 -0
- data/app/views/documents/new.html.haml +2 -0
- data/app/views/documents/show.html.haml +8 -0
- data/config/routes.rb +5 -0
- data/lib/appdoc/engine.rb +7 -0
- data/lib/appdoc/version.rb +3 -0
- data/lib/appdoc.rb +22 -0
- data/lib/generators/appdoc/appdoc_generator.rb +31 -0
- data/lib/generators/appdoc/templates/appdoc_config.rb +6 -0
- data/lib/generators/appdoc/templates/migration.rb +15 -0
- data/lib/generators/appdoc/templates/public/javascripts/SmartTextBox.js +962 -0
- data/lib/generators/appdoc/templates/public/stylesheets/jquery/smart_text_box/SmartTextBox.css +148 -0
- data/lib/generators/appdoc/templates/public/stylesheets/jquery/smart_text_box/imgs/close.gif +0 -0
- metadata +119 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
class DocumentsController < ApplicationController
|
2
|
+
|
3
|
+
filter_access_to :all
|
4
|
+
|
5
|
+
# GET /documents
|
6
|
+
def index
|
7
|
+
if params[:tag].blank?
|
8
|
+
@search = Document.search(params[:search])
|
9
|
+
else
|
10
|
+
@search = Document.tagged_with(params[:tag]).search(params[:search])
|
11
|
+
flash[:warn] = "No documents are tagged with \"#{params[:tag]}\"" if @search.count == 0 and params[:search].nil?
|
12
|
+
end
|
13
|
+
@documents = @search.page(params[:page]).per(20)
|
14
|
+
|
15
|
+
respond_to do |format|
|
16
|
+
format.html # index.html.haml
|
17
|
+
format.js { render :partial=>'documents' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /documents/1
|
22
|
+
def show
|
23
|
+
@document = Document.find_by_id(params[:id]) || Document.find_by_slug!(params[:id])
|
24
|
+
end
|
25
|
+
|
26
|
+
# GET /documents/new
|
27
|
+
def new
|
28
|
+
@document = Document.new
|
29
|
+
end
|
30
|
+
|
31
|
+
# GET /documents/1/edit
|
32
|
+
def edit
|
33
|
+
@document = Document.find_by_id(params[:id]) || Document.find_by_slug(params[:id])
|
34
|
+
end
|
35
|
+
|
36
|
+
# POST /documents
|
37
|
+
def create
|
38
|
+
@document = Document.new(params[:document])
|
39
|
+
|
40
|
+
if @document.save
|
41
|
+
flash[:notice] = 'Document was successfully created.'
|
42
|
+
redirect_to(@document)
|
43
|
+
else
|
44
|
+
render :action => 'new'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# PUT /documents/1
|
49
|
+
def update
|
50
|
+
|
51
|
+
@document = Document.find_by_id(params[:id]) || Document.find_by_slug(params[:id])
|
52
|
+
|
53
|
+
if @document.update_attributes(params[:document])
|
54
|
+
flash[:notice] = 'Document was successfully updated.'
|
55
|
+
redirect_to(@document)
|
56
|
+
else
|
57
|
+
render :action => 'edit'
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# DELETE /documents/1
|
63
|
+
def destroy
|
64
|
+
|
65
|
+
@document = Document.find_by_id(params[:id]) || Document.find_by_slug(params[:id])
|
66
|
+
@document.destroy
|
67
|
+
|
68
|
+
redirect_to(documents_url)
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Document < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :name, :content, :slug, :tag_list
|
4
|
+
validates_presence_of :name, :content, :slug
|
5
|
+
validates_uniqueness_of :name, :slug
|
6
|
+
|
7
|
+
before_validation :set_default_slug
|
8
|
+
|
9
|
+
default_scope :order => 'name'
|
10
|
+
|
11
|
+
scope :named, lambda {|name| select("DISTINCT documents.*").
|
12
|
+
joins("LEFT OUTER JOIN taggings ON (taggings.taggable_id = documents.id AND taggable_type = 'Document')").
|
13
|
+
joins("LEFT OUTER JOIN tags ON taggings.tag_id = tags.id").
|
14
|
+
where("documents.name LIKE ? OR documents.slug LIKE ? OR tags.name LIKE ?", "%#{name}%", "%#{name}%", "%#{name}%") }
|
15
|
+
|
16
|
+
search_methods :named
|
17
|
+
|
18
|
+
acts_as_taggable
|
19
|
+
|
20
|
+
def to_param
|
21
|
+
self.slug.blank? ? self.id.to_s : self.slug
|
22
|
+
end
|
23
|
+
|
24
|
+
def text_content
|
25
|
+
self.content.gsub(/<\/?[^>]*>/, '')
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_default_slug
|
29
|
+
self.slug = self.name.parameterize if self.slug.blank?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
.search.summary!=page_entries_info(@documents, :entry_name=>'document')
|
2
|
+
|
3
|
+
%table
|
4
|
+
%tr
|
5
|
+
%th.name Name
|
6
|
+
%th.content Content
|
7
|
+
%th.tags Tags
|
8
|
+
-@documents.each do |document|
|
9
|
+
%tr
|
10
|
+
%td.name!=link_to(document.name, document_path(document))
|
11
|
+
%td.content
|
12
|
+
%p&=document.text_content[0..100]
|
13
|
+
%td.tags
|
14
|
+
%ul.tags
|
15
|
+
-document.tags.each do |tag|
|
16
|
+
%li!=link_to(tag, {:controller=>'documents', :tag=>tag.to_s})
|
17
|
+
|
18
|
+
!=paginate(@documents)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
-content_for(:head) do
|
2
|
+
=javascript_include_tag('jquery-ui')
|
3
|
+
=javascript_include_tag('SmartTextBox')
|
4
|
+
=stylesheet_link_tag('jquery/smart_text_box/SmartTextBox')
|
5
|
+
:javascript
|
6
|
+
$(document).ready(function() {
|
7
|
+
// Tagging
|
8
|
+
$('#document_tag_list').smartTextBox({
|
9
|
+
submitChars: [#{Appdoc.delimiter.to_json}],
|
10
|
+
separator: ", ",
|
11
|
+
autocompleteValues: #{Appdoc.autocompleteValues.to_json},
|
12
|
+
minSearchLength: #{Appdoc.minSearchLength},
|
13
|
+
placeholder: #{Appdoc.placeholder.to_json}
|
14
|
+
});
|
15
|
+
});
|
16
|
+
|
17
|
+
=render('shared/wysiwyg')
|
18
|
+
|
19
|
+
=form_for(@document) do |f|
|
20
|
+
%dl
|
21
|
+
%dt.name=f.label :name
|
22
|
+
%dd.name=f.text_field :name
|
23
|
+
%dt.slug=f.label :slug
|
24
|
+
%dd.slug=f.text_field :slug
|
25
|
+
%dt.tags=f.label :tag_list, 'Tags'
|
26
|
+
%dd.tags
|
27
|
+
=f.text_field :tag_list, :maxlength => "15"
|
28
|
+
%span.help_text Lower case and separated by spaces
|
29
|
+
%dt.content=f.label :content
|
30
|
+
%dd.content=f.text_area :content
|
31
|
+
.buttons=f.submit 'Save'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
%h2 Documentation
|
2
|
+
|
3
|
+
=form_for(@search, :html=>{:class=>'search'}) do |f|
|
4
|
+
!=hidden_field_tag(:tag, params[:tag])
|
5
|
+
!=f.label(:named, 'Search')
|
6
|
+
!=f.text_field(:named)
|
7
|
+
!=f.submit('Search')
|
8
|
+
|
9
|
+
.search_results
|
10
|
+
!=render('documents', :documents=>@documents)
|
11
|
+
|
12
|
+
!=render('index_aside')
|
data/config/routes.rb
ADDED
data/lib/appdoc.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "appdoc/version"
|
2
|
+
|
3
|
+
module Appdoc
|
4
|
+
require 'appdoc/engine' if defined?(Rails)
|
5
|
+
require 'acts-as-taggable-on'
|
6
|
+
require 'declarative_authorization'
|
7
|
+
require 'haml'
|
8
|
+
require 'kaminari'
|
9
|
+
require 'meta_search'
|
10
|
+
|
11
|
+
# Settings
|
12
|
+
mattr_accessor(:delimiter)
|
13
|
+
mattr_accessor(:separator)
|
14
|
+
mattr_accessor(:autocompleteValues)
|
15
|
+
mattr_accessor(:minSearchLength)
|
16
|
+
mattr_accessor(:placeholder)
|
17
|
+
|
18
|
+
# for easy configuration
|
19
|
+
def self.config
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class AppdocGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
7
|
+
|
8
|
+
def self.next_migration_number(dirname)
|
9
|
+
sleep 1
|
10
|
+
if ActiveRecord::Base.timestamped_migrations
|
11
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
12
|
+
else
|
13
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_migration_files
|
18
|
+
migration_template "migration.rb", "db/migrate/appdoc_create_documents"
|
19
|
+
run "rails generate acts_as_taggable_on:migration"
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_initializer
|
23
|
+
template 'appdoc_config.rb', 'config/initializers/appdoc_config.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_related_files
|
27
|
+
copy_file 'public/stylesheets/jquery/smart_text_box/SmartTextBox.css', 'public/stylesheets/jquery/smart_text_box/SmartTextBox.css'
|
28
|
+
copy_file 'public/stylesheets/jquery/smart_text_box/imgs/close.gif', 'public/stylesheets/jquery/smart_text_box/imgs/close.gif'
|
29
|
+
copy_file 'public/javascripts/SmartTextBox.js', 'public/javascripts/SmartTextBox.js'
|
30
|
+
end
|
31
|
+
end
|