sqliki_generator 0.0.1 → 0.0.2

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/USAGE CHANGED
@@ -9,38 +9,22 @@ SYNOPSIS
9
9
  DESCRIPTION
10
10
  This generator creates a rudimentary SQL-based wiki.
11
11
 
12
- Included:
13
- - a User model which uses sha1 encryption for passwords
14
- - a Controller with signup, login, welcome and logoff actions
15
- - a mixin which lets you easily add advanced authentication
16
- features to your abstract base controller
17
- - a user_model.sql with the minimal sql required to get the model to work.
18
- - extensive unit and functional test cases to make sure nothing breaks.
19
-
20
12
  EXAMPLE
21
13
  ./script/generate sqliki Wiki
22
14
 
23
- This will generate a Wiki controller with the following methods:
24
-
25
- For users:
26
- index (=list)
27
- rollback
28
- wanted
29
- orphaned
30
- recently_revised
31
- find
32
- list
33
- show
34
- new
35
- edit
36
- For control flow:
37
- save
38
- raw
39
- html
40
- inplace_edit
41
- inplace_save
42
- create
43
- update
44
- destroy
15
+ This will generate a Wiki controller which provides users:
16
+ /wiki/index (==list) -- list all pages (alphabeticaly)
17
+ /wiki/wanted -- ..pages with no content
18
+ /wiki/orphaned -- ..pages that aren't linked to
19
+ /wiki/recently_revised -- ..pages in reverse order of edits
20
+ /wiki/show/(page) -- Show an existing page
21
+ /wiki/create/(page) -- Create a new page
22
+ /wiki/edit/(page) -- Edit an existing page
23
+ ...and additional methods for control flow / internal use:
24
+ /wiki/raw
25
+ /wiki/html
26
+ /wiki/inplace_edit
27
+ /wiki/destroy
28
+ /wiki/rollback/(draft)
45
29
 
46
30
  The tables are always called pages, drafts, and links
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  SPEC = Gem::Specification.new do |s|
4
4
  s.name = %q{sqliki_generator}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
  s.date = %q{2005-08-25}
7
7
  s.summary = %q{[Rails] SQL-based wiki generator.}
8
8
  s.require_paths = ["."]
@@ -16,21 +16,20 @@ SPEC = Gem::Specification.new do |s|
16
16
  templates/README
17
17
  templates/model_draft.rb
18
18
  templates/view_edit.rhtml
19
- templates/view_find.rhtml
20
19
  templates/view__form.rhtml
21
20
  templates/view_inplace_edit.rhtml
22
- templates/view_inplace_save.rhtml
23
21
  templates/view_list.rhtml
24
- templates/view_new.rhtml
22
+ templates/view_create.rhtml
25
23
  templates/view_rollback.rhtml
26
24
  templates/view_show.rhtml
27
25
  templates/model_link.rb
28
26
  templates/model_page.rb
29
27
  templates/controller_sqliki_controller.rb
30
28
  sqliki_generator.rb
31
- sqliki_generator-0.0.1.gemspec
29
+ sqliki_generator-0.0.2.gemspec
32
30
  }
33
- s.add_dependency(%q<rails>, [">= 0.13.1"])
31
+ s.add_dependency('rails', [">= 0.13.1"])
32
+ s.add_dependency('redcloth')
34
33
  end
35
34
 
36
35
  if $0 == __FILE__
data/sqliki_generator.rb CHANGED
@@ -2,10 +2,6 @@ class SqlikiGenerator < Rails::Generator::NamedBase
2
2
  def manifest
3
3
  record do |m|
4
4
 
5
- #
6
- # For v0.0.1, there's no renaming it
7
- file_name = 'sqliki'
8
-
9
5
  # Models.
10
6
  %w{page draft link}.each do |x|
11
7
  m.template "model_#{x}.rb",File.join("app/models", class_path, "#{x}.rb")
@@ -13,14 +9,11 @@ class SqlikiGenerator < Rails::Generator::NamedBase
13
9
 
14
10
  # Views.
15
11
  m.directory File.join("app/views", class_path, file_name)
16
- %w{edit find _form inplace_edit inplace_save list new rollback show }.each do |x|
12
+ %w{edit _form inplace_edit list create rollback show }.each do |x|
17
13
  m.template "view_#{x}.rhtml",File.join("app/views", class_path, file_name, "#{x}.rhtml")
18
14
  end
19
15
 
20
- # Controller.
21
- %w{sqliki}.each do |x|
22
- m.template "controller_#{x}_controller.rb",File.join("app/controllers", class_path, "#{x}_controller.rb")
23
- end
16
+ m.template "controller_sqliki_controller.rb",File.join("app/controllers", class_path, "#{file_name}_controller.rb")
24
17
 
25
18
  # Libs.
26
19
  %w{sanitize_html}.each do |x|
data/templates/README CHANGED
@@ -84,5 +84,12 @@ CREATE TABLE links (
84
84
 
85
85
  == Changelog
86
86
 
87
- 0.0.1 First gem release
88
-
87
+ 0.0.1
88
+ First gem release
89
+ 0.0.2
90
+ Made the name of the controller changeable
91
+ Removed the system specific path for RedCloth
92
+ Implemented Orphaned/Wanted/Recently_revised
93
+ Cleaned up the controller interface (w. the the
94
+ trick from Tobias Luetke's Postback Generator)
95
+
@@ -1,9 +1,9 @@
1
- class SqlikiController < ApplicationController
1
+ class <%= class_name %>Controller < ApplicationController
2
2
  model :draft
3
3
  include LoginSystem
4
4
  before_filter :login_required
5
5
  def identify_page
6
- @page ||= Page.find_by_title(params[:id]) #|| Page.find_by_id(params[:id])
6
+ @page ||= Page.find_by_title(params[:id])
7
7
  end
8
8
  def index
9
9
  list
@@ -15,62 +15,61 @@ class SqlikiController < ApplicationController
15
15
  def html
16
16
  render_text identify_page.current_draft.html
17
17
  end
18
- def inplace_edit
19
- edit
20
- end
21
18
  def rollback
22
19
  identify_page
23
20
  #@page.current_draft = ???
24
21
  render :action => 'show'
25
22
  end
26
- def save
27
- end
28
- def inplace_save
29
- save
30
- end
31
23
  def wanted
24
+ list :wanted
25
+ render :action => 'list'
32
26
  end
33
27
  def orphaned
28
+ list :orphaned
29
+ render :action => 'list'
34
30
  end
35
31
  def recently_revised
36
- end
37
- def find
32
+ list :recently_revised
33
+ render :action => 'list'
38
34
  end
39
35
  def list(condition=:all)
40
- @page_pages, @pages = paginate :page, :per_page => 10
36
+ @page_pages, @pages = paginate :page, {:per_page => 20}.merge(case condition
37
+ when :wanted then {:conditions => 'current_draft_id IS NULL'}
38
+ when :orphaned then {
39
+ :join => 'p LEFT JOIN links l ON l.page_id = p.id left join drafts dx on dx.id = l.draft_id left join pages px on px.current_draft_id = dx.id',
40
+ :conditions => 'page_id IS NULL'
41
+ }
42
+ when :recently_revised then {:order_by => 'updated_on DESC'}
43
+ else {:order_by => 'title'}
44
+ end)
41
45
  end
42
46
  def show
43
- identify_page || redirect_to(:action => 'new', :id => @params[:id])
44
- end
45
- def new
46
- @page = Page.new_page(@params[:id])
47
+ identify_page || redirect_to(:action => 'create', :id => @params[:id])
47
48
  end
48
49
  def create
49
- new
50
- @page.save
51
- if @page.update_attributes(params[:page])
52
- #@page.current_draft.created_by = @session[:user]
53
- #@page.save
50
+ @page = Page.new_page(@params[:id])
51
+ if @request.post? and @page.update_attributes(params[:page]) and @page.save
54
52
  flash[:notice] = 'Page was successfully created.'
55
- redirect_to :action => 'list'
56
- else
57
- render :action => 'new'
53
+ redirect_to :action => 'show', :id => @page.title
58
54
  end
59
55
  end
60
- def edit
61
- identify_page || redirect_to(:action => 'new', :id => @params[:id])
56
+ def inplace_edit
57
+ if not identify_page
58
+ redirect_to(:action => 'create', :id => @params[:id])
59
+ elsif @request.post? and @page.update_attributes(params[:page])
60
+ redirect_to :action => 'html', :id => @page.title
61
+ end
62
62
  end
63
- def update
64
- identify_page
65
- if @page.update_attributes(params[:page])
63
+ def edit
64
+ if not identify_page
65
+ redirect_to(:action => 'create', :id => @params[:id])
66
+ elsif @request.post? and @page.update_attributes(params[:page])
66
67
  flash[:notice] = 'Page was successfully updated.'
67
68
  redirect_to :action => 'show', :id => @page.title
68
- else
69
- render :action => 'edit'
70
69
  end
71
70
  end
72
71
  def destroy
73
- identify_page.destroy
72
+ identify_page.destroy if @request.post?
74
73
  redirect_to :action => 'list'
75
74
  end
76
75
  end
@@ -1,5 +1,5 @@
1
1
  require 'sanitize_html'
2
- require '/usr/local/lib/ruby/gems/1.8/gems/RedCloth-3.0.3/lib/redcloth'
2
+ require 'redcloth'
3
3
 
4
4
  class Draft < ActiveRecord::Base
5
5
  acts_as_tree :foreign_key => 'based_on_draft_id'
@@ -15,27 +15,15 @@ class Draft < ActiveRecord::Base
15
15
  end
16
16
  class RopaRojo < RedCloth
17
17
  def hard_break(text)
18
- make_divs text
18
+ @rules.each do |rule_name|
19
+ method( rule_name ).call( text ) if rule_name.to_s.match /^pre_/
20
+ end
19
21
  super
20
22
  end
21
23
  def to_html(*rules,&callback)
22
24
  @callback = callback
23
25
  rules = DEFAULT_RULES if rules.empty?
24
- text = super(*([:inline_wiki_words]+rules))
25
- text << %q{
26
- <script type="text/javascript" language="JavaScript">
27
- <!--
28
- function toggle(name) {
29
- q=document.getElementById(name);
30
- if (q.style.display == 'none')
31
- {q.style.display = 'block';}
32
- else
33
- {q.style.display = 'none';};
34
- }
35
- //-->
36
- </script>
37
- } if @need_toggle_function
38
- text
26
+ text = super(*([:pre_wiki_words,:pre_make_divs,:post_add_toggle]+rules))
39
27
  end
40
28
  def htmlesc(str,mode)
41
29
  super
@@ -73,7 +61,7 @@ class Draft < ActiveRecord::Base
73
61
  /mx
74
62
  DIV_RE = /#{ALT_TEXT}#{DIV_BRACKETS}/m
75
63
 
76
- def make_divs( text )
64
+ def pre_make_divs( text )
77
65
  ## break the text into <div> blocks based on {{{ ... }}}
78
66
  while text.gsub!( DIV_RE ) { |m|
79
67
  has_link,pre,atts,link_text,title,div_block = $~.captures
@@ -88,6 +76,21 @@ class Draft < ActiveRecord::Base
88
76
  }; end
89
77
  text
90
78
  end
79
+ def post_add_toggle(text)
80
+ text << %q{
81
+ <script type="text/javascript" language="JavaScript">
82
+ <!--
83
+ function toggle(name) {
84
+ q=document.getElementById(name);
85
+ if (q.style.display == 'none')
86
+ {q.style.display = 'block';}
87
+ else
88
+ {q.style.display = 'none';};
89
+ }
90
+ //-->
91
+ </script>
92
+ } if @need_toggle_function
93
+ end
91
94
  NOT_WIKI_WORD = /\\(([A-Z]+[a-z0-9]+){2,})/
92
95
  WIKI_WORD = /#{ALT_TEXT}(([A-Z]+[a-z1-9]+){2,})/
93
96
  WIKI_PHRASE = /#{ALT_TEXT}\[\[(.*?)\]\]/m
@@ -95,33 +98,26 @@ class Draft < ActiveRecord::Base
95
98
  ww.gsub(/([a-z0-9])([A-Z])/,'\1 \2');
96
99
  end
97
100
  def clean_wiki_word(ww)
98
- ww.gsub(/ /,'_').gsub(/[^A-Za-z0-9$-_.+!*'(),]/,'')
101
+ ww.gsub(/[^A-Za-z0-9$-_.+!*'(),]/,'')
99
102
  end
100
103
  include ActionView::Helpers::TagHelper
101
104
  include ActionView::Helpers::UrlHelper
102
- #def wiki_link(ww)
103
- # #link_to ww, {:controller => 'sqliki', :action => 'show', :id => clean_wiki_word(ww)}
104
- # link_to ww, "/sqliki/show/#{clean_wiki_word(ww)}"
105
- # end
106
105
  def wiki_link(link_text,ww)
107
- #link_to link_text, {:controller => 'sqliki', :action => 'show', :id => clean_wiki_word(ww)}
108
- #(@callback && @callback.call(:wiki_link,link_text,ww)) || (link_to link_text, "/sqliki/show/#{clean_wiki_word(ww)}")
109
- (@callback && @callback.call(:wiki_link,link_text,ww))
110
- (link_to link_text, "/sqliki/show/#{clean_wiki_word(ww)}")
106
+ (@callback && @callback.call(:wiki_link,link_text,ww)) ||
107
+ (link_to link_text, "/<%= file_name %>/show/#{clean_wiki_word(ww)}")
111
108
  end
112
- def inline_wiki_words(text)
109
+ def pre_wiki_words(text)
113
110
  text.gsub!(NOT_WIKI_WORD) { |m| shelve $1 }
114
111
  [WIKI_PHRASE,WIKI_WORD].each {|pattern|
115
112
  text.gsub!(pattern) { |m|
116
113
  has_link,pre,atts,link_text,title,ww = $~.captures
117
114
  ww = split_wiki_word(ww) if pattern == WIKI_WORD
118
- (pre||'') + wiki_link("<span #{shelve(pba(atts))}>#{link_text||ww}</span>"||ww,ww)
115
+ (pre||'') + shelve(wiki_link("<span #{pba(atts)}>#{link_text||ww}</span>",ww))
119
116
  }
120
117
  }
121
118
  text
122
119
  end
123
120
  end
124
- #include ActionView::Helpers::TextHelper
125
121
  def textilize(body) #html
126
122
  if body.blank?
127
123
  ""
File without changes
@@ -1,9 +1,9 @@
1
1
  <h1><%%= @page.title %></h1>
2
2
 
3
- <%%= start_form_tag :action => 'update', :id => @page.title %>
3
+ <%%= start_form_tag :action => 'edit', :id => @page.title %>
4
4
  <%%= render_partial 'form' %>
5
- <%%= submit_tag 'Edit' %>
5
+ <%%= submit_tag 'Save changes' %>
6
+ <%%= link_to 'Cancle changes', :action => 'show', :id => @page.title %>
6
7
  <%%= end_form_tag %>
7
8
 
8
- <%%= link_to 'Show', :action => 'show', :id => @page.title %> |
9
- <%%= link_to 'List', :action => 'list' %>
9
+
@@ -6,14 +6,11 @@
6
6
 
7
7
  <%% for page in @pages %>
8
8
  <tr>
9
- <td><%%= page.title %></td>
9
+ <td><%%= link_to page.title, :action => 'show', :id => page.title %></td>
10
10
  <td><%%= page.author.login %></td>
11
11
  <td><%%= page.created_on %></td>
12
12
  <td><%%= page.current_draft.author.login %></td>
13
13
  <td><%%= page.current_draft.created_on %></td>
14
- <td><%%= link_to 'Show', :action => 'show', :id => page.title %></td>
15
- <td><%%= link_to 'Edit', :action => 'edit', :id => page.title %></td>
16
- <td><%%= link_to 'Destroy', {:action => 'destroy', :id => page.title}, :confirm => 'Are you sure?' %></td>
17
14
  </tr>
18
15
  <%% end %>
19
16
  </table>
@@ -23,4 +20,4 @@
23
20
 
24
21
  <br />
25
22
 
26
- <%%= link_to 'New page', :action => 'new' %>
23
+ <%%= link_to 'New page', :action => 'create' %>
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: sqliki_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
6
+ version: 0.0.2
7
7
  date: 2005-08-25
8
8
  summary: "[Rails] SQL-based wiki generator."
9
9
  require_paths:
@@ -32,19 +32,17 @@ files:
32
32
  - templates/README
33
33
  - templates/model_draft.rb
34
34
  - templates/view_edit.rhtml
35
- - templates/view_find.rhtml
36
35
  - templates/view__form.rhtml
37
36
  - templates/view_inplace_edit.rhtml
38
- - templates/view_inplace_save.rhtml
39
37
  - templates/view_list.rhtml
40
- - templates/view_new.rhtml
38
+ - templates/view_create.rhtml
41
39
  - templates/view_rollback.rhtml
42
40
  - templates/view_show.rhtml
43
41
  - templates/model_link.rb
44
42
  - templates/model_page.rb
45
43
  - templates/controller_sqliki_controller.rb
46
44
  - sqliki_generator.rb
47
- - sqliki_generator-0.0.1.gemspec
45
+ - sqliki_generator-0.0.2.gemspec
48
46
  test_files: []
49
47
  rdoc_options: []
50
48
  extra_rdoc_files: []
@@ -61,4 +59,14 @@ dependencies:
61
59
  - ">="
62
60
  - !ruby/object:Gem::Version
63
61
  version: 0.13.1
62
+ version:
63
+ - !ruby/object:Gem::Dependency
64
+ name: redcloth
65
+ version_requirement:
66
+ version_requirements: !ruby/object:Gem::Version::Requirement
67
+ requirements:
68
+ -
69
+ - ">"
70
+ - !ruby/object:Gem::Version
71
+ version: 0.0.0
64
72
  version:
@@ -1,2 +0,0 @@
1
- <h1>Page#find</h1>
2
- <p>Find me in app/views/page/find.rhtml</p>
@@ -1,2 +0,0 @@
1
- <h1>Page#inplace_save</h1>
2
- <p>Find me in app/views/page/inplace_save.rhtml</p>