clipster 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/MIT-LICENSE +20 -20
  2. data/README.rdoc +53 -52
  3. data/Rakefile +34 -34
  4. data/app/assets/javascripts/clipster/application.js +15 -15
  5. data/app/assets/javascripts/clipster/bootstrap.js +2026 -2026
  6. data/app/assets/javascripts/clipster/bootstrap.min.js +5 -5
  7. data/app/assets/javascripts/clipster/clip.js +2 -2
  8. data/app/assets/javascripts/clipster/clips.js +2 -2
  9. data/app/assets/stylesheets/clipster/application.css +27 -15
  10. data/app/assets/stylesheets/clipster/bootstrap.css +5774 -5774
  11. data/app/assets/stylesheets/clipster/clip.css +21 -21
  12. data/app/assets/stylesheets/clipster/clips.css +4 -4
  13. data/app/controllers/clipster/application_controller.rb +7 -7
  14. data/app/controllers/clipster/clips_controller.rb +80 -67
  15. data/app/helpers/clipster/application_helper.rb +4 -4
  16. data/app/helpers/clipster/clip_helper.rb +4 -4
  17. data/app/helpers/clipster/clips_helper.rb +4 -4
  18. data/app/models/clipster/clip.rb +74 -23
  19. data/app/views/clipster/clips/about.html.erb +15 -0
  20. data/app/views/clipster/clips/create.html.erb +46 -36
  21. data/app/views/clipster/clips/expired.html.erb +1 -0
  22. data/app/views/clipster/clips/list.html.erb +43 -37
  23. data/app/views/clipster/clips/show.html.erb +7 -5
  24. data/app/views/kaminari/_first_page.html.erb +3 -0
  25. data/app/views/kaminari/_gap.html.erb +3 -0
  26. data/app/views/kaminari/_last_page.html.erb +3 -0
  27. data/app/views/kaminari/_next_page.html.erb +3 -0
  28. data/app/views/kaminari/_page.html.erb +3 -0
  29. data/app/views/kaminari/_paginator.html.erb +17 -0
  30. data/app/views/kaminari/_prev_page.html.erb +3 -0
  31. data/app/views/layouts/clipster/application.html.erb +49 -48
  32. data/config/routes.rb +14 -13
  33. data/config/schedule.rb +10 -0
  34. data/db/migrate/20121004010757_create_clipster_clips.rb +16 -16
  35. data/db/migrate/20121007154400_add_hash_index_to_clips.rb +13 -13
  36. data/db/migrate/20121007155125_populate_clip_defaults.rb +21 -21
  37. data/db/migrate/20121007162741_rename_hash_to_url_hash.rb +9 -9
  38. data/db/migrate/20121007223358_remove_default_from_language.rb +9 -9
  39. data/db/migrate/20121007223631_set_default_title_to_untitled.rb +9 -9
  40. data/db/migrate/20121105212724_add_lifespan_to_clips.rb +9 -0
  41. data/lib/clipster/engine.rb +15 -14
  42. data/lib/clipster/version.rb +3 -3
  43. data/lib/clipster.rb +4 -4
  44. data/lib/tasks/clipster_tasks.rake +4 -4
  45. metadata +46 -3
@@ -1,22 +1,22 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
5
-
6
- .bordered {
7
- border: 1px solid #dddddd;
8
- border-collapse: separate;
9
- *border-collapse: collapse;
10
- /*border-left: 0;*/
11
- -webkit-border-radius: 4px;
12
- -moz-border-radius: 4px;
13
- border-radius: 4px;
14
- }
15
-
16
- .bordered div {
17
- margin: 5px;
18
- }
19
-
20
- .title {
21
- border-bottom: 1px solid #ddd;
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .bordered {
7
+ border: 1px solid #dddddd;
8
+ border-collapse: separate;
9
+ *border-collapse: collapse;
10
+ /*border-left: 0;*/
11
+ -webkit-border-radius: 4px;
12
+ -moz-border-radius: 4px;
13
+ border-radius: 4px;
14
+ }
15
+
16
+ .bordered div {
17
+ margin: 5px;
18
+ }
19
+
20
+ .title {
21
+ border-bottom: 1px solid #ddd;
22
22
  }
@@ -1,4 +1,4 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -1,7 +1,7 @@
1
- module Clipster
2
- class ApplicationController < ActionController::Base
3
- def index
4
- render :text => "Welcome 2 Clipster"
5
- end
6
- end
7
- end
1
+ module Clipster
2
+ class ApplicationController < ActionController::Base
3
+ def index
4
+ render :text => "Welcome 2 Clipster"
5
+ end
6
+ end
7
+ end
@@ -1,67 +1,80 @@
1
- require_dependency "clipster/application_controller"
2
-
3
- module Clipster
4
- class ClipsController < ApplicationController
5
- def index
6
- create
7
- render 'create'
8
- end
9
-
10
- def list
11
- # get all clips, with the newest clip first
12
- # TODO: look into pagination and any other info
13
- @clips = Clip.where(:private => false).order('created_at DESC')
14
-
15
- # you have to love the activerelation queries don't you
16
- # should probably move to one query for performance if that becomes an issue
17
- # or we have a large
18
- @clips = @clips.where(:language => params[:lang]) unless params[:lang].nil?
19
-
20
- @languages = Clip.select("language, count(*) as count").group(:language)
21
- end
22
-
23
- def create
24
- @clip = Clip.new(params[:clip])
25
-
26
- #only do validation if something was actually posted.
27
- if !params[:clip].nil? && @clip.valid?
28
- @clip.save
29
- redirect_to @clip
30
- return #early return so we don't have else statement
31
- end
32
-
33
- # Get all languages we have syntax for and remove debugging languages.
34
- @languages = get_languages
35
- end
36
-
37
- def show
38
- @clip = Clip.find(params[:id])
39
- cr_scanner = CodeRay.scan(@clip.clip, @clip.language)
40
-
41
- # Only show line numbers if its greater than 1
42
- @clip_div = cr_scanner.div
43
- @clip_div = cr_scanner.div(:line_numbers => :table) unless cr_scanner.loc <= 1
44
- end
45
-
46
- def search
47
- @clips = Clip.search(params[:search_term])
48
-
49
- p '\n\n\n\n'
50
- p @clips
51
-
52
- @languages = Clip.select("language, count(*) as count").group(:language)
53
-
54
- render 'list' unless @clips.nil?
55
- end
56
-
57
- private
58
-
59
- def get_languages
60
- languages = CodeRay::Scanners.all_plugins
61
- languages.delete(CodeRay::Scanners::Raydebug)
62
- languages.delete(CodeRay::Scanners::Debug)
63
-
64
- languages
65
- end
66
- end
67
- end
1
+ require_dependency "clipster/application_controller"
2
+
3
+ module Clipster
4
+ class ClipsController < ApplicationController
5
+ def index
6
+ create
7
+ render 'create'
8
+ end
9
+
10
+ def list
11
+ # get all clips, with the newest clip first
12
+ if params[:lang].nil?
13
+ @clips = Clip.public.order('created_at DESC').page(params[:page])
14
+ else
15
+ @clips = Clip.language_for_public(params[:lang]).order('created_at DESC').page(params[:page])
16
+ end
17
+
18
+ @languages = Clip.public.select("language, count(*) as count").group(:language)
19
+ end
20
+
21
+ def create
22
+ @clip = Clip.new(params[:clip])
23
+
24
+ #only do validation if something was actually posted.
25
+ if !params[:clip].nil? && @clip.valid?
26
+ @clip.save
27
+ redirect_to @clip
28
+ return #early return so we don't have else statement
29
+ end
30
+
31
+ # Get all languages we have syntax for and remove debugging languages.
32
+ @languages = get_languages
33
+ end
34
+
35
+ def show
36
+ @clip = Clip.where("url_hash = :id and (expires is null OR expires > :now)",{
37
+ :id => params[:id],
38
+ :now => DateTime.now
39
+ }).first
40
+
41
+ if @clip.nil?
42
+ # Most likely the clip is expired, take advantage of this time to
43
+ # clean up all expired clips, then display error page
44
+ Clip.delete_expired_clips
45
+ render :expired
46
+ return
47
+ end
48
+
49
+ cr_scanner = CodeRay.scan(@clip.clip, @clip.language)
50
+
51
+ # Only show line numbers if its greater than 1
52
+ @clip_div = cr_scanner.div
53
+ @clip_div = cr_scanner.div(:line_numbers => :table) unless cr_scanner.loc <= 1
54
+ end
55
+
56
+ def search
57
+ @clips = Clip.search(params[:search_term])
58
+
59
+ p '\n\n\n\n'
60
+ p @clips
61
+
62
+ @languages = Clip.select("language, count(*) as count").group(:language)
63
+
64
+ render 'list' unless @clips.nil?
65
+ end
66
+
67
+ def about
68
+ end
69
+
70
+ private
71
+
72
+ def get_languages
73
+ languages = CodeRay::Scanners.all_plugins
74
+ languages.delete(CodeRay::Scanners::Raydebug)
75
+ languages.delete(CodeRay::Scanners::Debug)
76
+
77
+ languages
78
+ end
79
+ end
80
+ end
@@ -1,4 +1,4 @@
1
- module Clipster
2
- module ApplicationHelper
3
- end
4
- end
1
+ module Clipster
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Clipster
2
- module ClipHelper
3
- end
4
- end
1
+ module Clipster
2
+ module ClipHelper
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Clipster
2
- module ClipsHelper
3
- end
4
- end
1
+ module Clipster
2
+ module ClipsHelper
3
+ end
4
+ end
@@ -1,23 +1,74 @@
1
- module Clipster
2
- class Clip < ActiveRecord::Base
3
- before_create :init_id
4
- self.primary_key = :url_hash
5
- attr_accessible :clip, :language, :title, :private
6
-
7
- # scope utilized by search functionality.
8
- # TODO: build more powerful search term creation
9
- scope :search, lambda {|term|
10
- where("title LIKE :term or language LIKE :term or clip LIKE :term",{
11
- :term => term
12
- })
13
- }
14
-
15
- validates :clip, :length => {:minimum => 3}
16
- validates :title, :length => {:minimum => 1}
17
-
18
- private
19
- def init_id
20
- self.url_hash = Time.now.to_f.to_s.gsub('.','').to_i.to_s(36)
21
- end
22
- end
23
- end
1
+ module Clipster
2
+ class Clip < ActiveRecord::Base
3
+ include ActionView::Helpers::DateHelper
4
+ before_create :init_id
5
+ self.primary_key = :url_hash
6
+ attr_accessible :clip, :language, :title, :private, :expires, :lifespan
7
+ cattr_reader :lifespans
8
+
9
+ # Define all supported lifespans and their time offset
10
+ @@lifespans = {"Forever" => nil,
11
+ "An Hour" => {:hours=>1},
12
+ "A Week" => {:days=>7},
13
+ "A Day" => {:days=>1},
14
+ "A Month" => {:months=>1},
15
+ "A Year" => {:years=>1}}
16
+
17
+ # TODO: build more powerful search term creation
18
+ scope :search, lambda {|term|
19
+ where("(title LIKE :term or language LIKE :term or clip LIKE :term) and (expires is null OR expires > :now)",{
20
+ :term => term,
21
+ :now => DateTime.now
22
+ })
23
+ }
24
+
25
+ # All clips that are public, language specific, and not expired
26
+ scope :language_for_public, lambda {|lang|
27
+ where("private = :private AND
28
+ language = :lang AND
29
+ (expires is null OR expires > :now)",{
30
+ :private => false,
31
+ :lang => lang,
32
+ :now => DateTime.now
33
+ })
34
+ }
35
+
36
+ # All clips that are public, and not expired
37
+ scope :public, lambda {
38
+ where("private = :private AND
39
+ (expires is null OR expires > :now)",{
40
+ :private => false,
41
+ :now => DateTime.now
42
+ })
43
+ }
44
+
45
+ validates :clip, :length => {:minimum => 3}
46
+ validates :title, :length => {:minimum => 1}
47
+
48
+ # Setter to convert user's choice of 'A Week', etc. to an actual DateTime
49
+ def lifespan=(lifespan)
50
+ unless @@lifespans[lifespan].nil?
51
+ self.expires = DateTime.now.advance(@@lifespans[lifespan])
52
+ end
53
+ end
54
+
55
+ # Getter to convert an expire date to '1 Month', '1 Year', etc.
56
+ def lifespan
57
+ unless self.expires.nil?
58
+ time_ago_in_words(self.expires)
59
+ else
60
+ "the end of time"
61
+ end
62
+ end
63
+
64
+ # Utility method called by either cron job or when an expired clip is accessed
65
+ def Clip.delete_expired_clips
66
+ Clip.destroy_all(["expires is not null AND expires <= ?", DateTime.now])
67
+ end
68
+
69
+ private
70
+ def init_id
71
+ self.url_hash = Time.now.to_f.to_s.gsub('.','').to_i.to_s(36)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ <legend>About Clipster</legend>
2
+
3
+ <div class="span10 offset1">
4
+ <p>Clipster is an Open Source Rails engine to add clipboard code sharing to your existing Ruby on Rails applications. Complete with syntax highlighting and expiring clips, its great for internal code sharing. Please visit us on <%= link_to("GitHub", "http://github.com/kwbock/clipster") %> for downloads and support.</p>
5
+ </div>
6
+
7
+ <div class="well span9 offset1">
8
+ <p>Copyright 2012 Kyle Bock, Daniel White</p>
9
+
10
+ <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
11
+
12
+ <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<p>
13
+
14
+ <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
15
+ </div>
@@ -1,37 +1,47 @@
1
- <legend>New Clip</legend>
2
-
3
- <%= form_for(@clip, :url => { :action => "create" }) do |f| %>
4
- <%= f.error_messages %>
5
-
6
- <!-- title -->
7
- <div class="span4 offset1">
8
- <%= f.label(:title) %>
9
- <%= f.text_field(:title, :value => @clip.title) %>
10
- </div>
11
- <!-- /title -->
12
-
13
- <!-- language -->
14
- <div class="span4 offset1 pull-right">
15
- <%= f.label(:language) %>
16
- <%= f.collection_select("language", @languages, :lang, :title, :selected => (@clip.language || "text")) %>
17
- </div>
18
- <!-- /language -->
19
-
20
- <!-- clip -->
21
- <div class="span10 offset1">
22
- <%= f.label(:clip) %>
23
- <%= f.text_area(:clip, :class=>"span10", :rows=>"10", :value => @clip.clip) %>
24
- </div>
25
- <!-- /clip -->
26
-
27
- <!-- private -->
28
- <div class="span4 offset1">
29
- <%= f.label(:private) %>
30
- <%= f.check_box(:private, :value => @clip.private) %>
31
- </div>
32
- <!-- /private -->
33
-
34
- <div class="span2 pull-right">
35
- <%= f.submit(:class=>"btn btn-primary") %>
36
- </div>
1
+ <legend>New Clip</legend>
2
+
3
+ <%= form_for(@clip, :url => { :action => "create" }) do |f| %>
4
+ <%= f.error_messages %>
5
+
6
+ <!-- title -->
7
+ <div class="span5 offset1">
8
+ <div class="span4 no-left">
9
+ <%= f.label(:title) %>
10
+ <%= f.text_field(:title, :value => @clip.title, :required=>"required") %>
11
+ </div>
12
+ <!-- /title -->
13
+
14
+ <!-- language -->
15
+ <div class="span4 no-left">
16
+ <%= f.label(:language) %>
17
+ <%= f.collection_select("language", @languages, :lang, :title, :selected => (@clip.language || "text")) %>
18
+ </div>
19
+ <!-- /language -->
20
+ </div>
21
+ <div class="span5 offset1 pull-right no-left">
22
+ <!-- lifespan -->
23
+ <div class="span4">
24
+ <%= f.label(:lifespan) %>
25
+ <%= f.select(:lifespan, @clip.lifespans) %>
26
+ </div>
27
+ <!-- /lifespan -->
28
+
29
+ <!-- private -->
30
+ <div class="span4">
31
+ <%= f.label(:private) %>
32
+ <%= f.check_box(:private, :value => @clip.private) %>
33
+ </div>
34
+ <!-- /private -->
35
+ </div>
36
+
37
+ <!-- clip -->
38
+ <div class="span10 offset1">
39
+ <%= f.label(:clip) %>
40
+ <%= f.text_area(:clip, :class=>"span10", :rows=>"15", :value => @clip.clip, :required=>"required") %>
41
+ </div>
42
+ <!-- /clip -->
43
+
44
+ <div class="span2 pull-right">
45
+ <%= f.submit(:class=>"btn btn-primary") %>
46
+ </div>
37
47
  <% end %>
@@ -0,0 +1 @@
1
+ <div class="span10 offset4 text-error">Sorry, This is an invalid clip or it has expired.</div>
@@ -1,38 +1,44 @@
1
- <legend>Recent Clips <%= "- #{params[:lang]}" unless params[:lang].nil? %></legend>
2
- <div class="span7">
3
- <table class="table table-striped table-bordered table-hover span6">
4
- <thead>
5
- <tr>
6
- <th>
7
- Title
8
- </th>
9
- <th>
10
- Language
11
- </th>
12
- <th>
13
- Created On
14
- </th>
15
- </tr>
16
- </thead>
17
- <tbody>
18
- <% @clips.each do |clip| %>
19
- <tr>
20
- <td><%= link_to clip.title, clip %></td>
21
- <td><%= clip.language %></td>
22
- <td><%= l clip.created_at, :format => :short %></td>
23
- </tr>
24
- <% end %>
25
- <% unless @clips.length > 0 %>
26
- <tr>
27
- <td colspan="3" style="text-align: center;">There are no public clips.</td>
28
- </tr>
29
- <% end %>
30
- </tbody>
31
- </table>
32
- </div>
33
- <aside class="languages bordered span3 offset1">
34
- <div class="title">Languages</div>
35
- <% @languages.each do |lang| %>
36
- <div><%= link_to lang.language, list_clips_path(:lang => lang.language) %> (<%= lang.count %>)</div>
37
- <% end %>
1
+ <legend>Recent Clips <%= "- #{params[:lang]}" unless params[:lang].nil? %></legend>
2
+ <div class="span7">
3
+ <table class="table table-striped table-bordered table-hover span6">
4
+ <thead>
5
+ <tr>
6
+ <th>
7
+ Title
8
+ </th>
9
+ <th>
10
+ Language
11
+ </th>
12
+ <th>
13
+ Created On
14
+ </th>
15
+ <th>
16
+ Expires
17
+ </th>
18
+ </tr>
19
+ </thead>
20
+ <tbody>
21
+ <% @clips.each do |clip| %>
22
+ <tr>
23
+ <td><%= link_to clip.title, clip %></td>
24
+ <td><%= clip.language %></td>
25
+ <td><%= l clip.created_at, :format => :short %></td>
26
+ <td><%= clip.lifespan %></td>
27
+ </tr>
28
+ <% end %>
29
+ <% unless @clips.length > 0 %>
30
+ <tr>
31
+ <td colspan="3" style="text-align: center;">There are no public clips.</td>
32
+ </tr>
33
+ <% end %>
34
+ </tbody>
35
+ </table>
36
+ <div class="clearfix"></div>
37
+ <%= paginate @clips %>
38
+ </div>
39
+ <aside class="languages bordered span3 offset1">
40
+ <div class="title">Languages</div>
41
+ <% @languages.each do |lang| %>
42
+ <div><%= link_to lang.language, list_clips_path(:lang => lang.language) %> (<%= lang.count %>)</div>
43
+ <% end %>
38
44
  </aside>
@@ -1,6 +1,8 @@
1
- <legend>
2
- Title: <%=@clip.title%></br>
3
- Language: <%=@clip.language%>
4
- </legend>
5
-
1
+ <legend>
2
+ <div class="span10"><%=@clip.title %></div>
3
+ <div class="span3 secondary">A <%=@clip.language.capitalize %> clip</div>
4
+ <div class="span5 secondary">Expires: <%= @clip.lifespan.humanize %></div>
5
+ <div class="clearfix"></div>
6
+ </legend>
7
+ <div class="clearfix"></div>
6
8
  <%= @clip_div.html_safe %>
@@ -0,0 +1,3 @@
1
+ <li>
2
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li class="disabled">
2
+ <%= link_to raw(t 'views.pagination.truncate'), '#' %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li>
2
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li>
2
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
3
+ </li>
@@ -0,0 +1,3 @@
1
+ <li class="<%= 'active' if page.current? %>">
2
+ <%= link_to page, page.current? ? '#' : url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
3
+ </li>
@@ -0,0 +1,17 @@
1
+ <%= paginator.render do -%>
2
+ <div class="pagination">
3
+ <ul>
4
+ <%= first_page_tag unless current_page.first? %>
5
+ <%= prev_page_tag unless current_page.first? %>
6
+ <% each_page do |page| -%>
7
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
8
+ <%= page_tag page %>
9
+ <% elsif !page.was_truncated? -%>
10
+ <%= gap_tag %>
11
+ <% end -%>
12
+ <% end -%>
13
+ <%= next_page_tag unless current_page.last? %>
14
+ <%= last_page_tag unless current_page.last? %>
15
+ </ul>
16
+ </div>
17
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <li>
2
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
3
+ </li>