social_stream-linkser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gitignore +14 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +5 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +6 -0
  6. data/Rakefile +26 -0
  7. data/app/assets/javascripts/linkser.js.erb +0 -0
  8. data/app/assets/javascripts/social_stream-linkser.js +1 -0
  9. data/app/assets/stylesheets/linkser.css.scss +41 -0
  10. data/app/assets/stylesheets/social_stream-linkser.css +3 -0
  11. data/app/controllers/links_controller.rb +3 -0
  12. data/app/controllers/linkser_controller.rb +22 -0
  13. data/app/models/link.rb +34 -0
  14. data/app/views/links/_link.html.erb +24 -0
  15. data/app/views/links/_link_preview.html.erb +25 -0
  16. data/app/views/links/_link_with_details.html.erb +4 -0
  17. data/app/views/links/create.js.erb +15 -0
  18. data/app/views/links/destroy.js.erb +1 -0
  19. data/app/views/links/show.html.erb +10 -0
  20. data/app/views/posts/_new_activity_fields.erb +53 -0
  21. data/config/locales/en.yml +14 -0
  22. data/config/locales/es.yml +14 -0
  23. data/config/routes.rb +3 -0
  24. data/db/migrate/20111129100618_create_social_stream_linkser.rb +21 -0
  25. data/lib/generators/social_stream/linkser/install_generator.rb +24 -0
  26. data/lib/social_stream-linkser.rb +16 -0
  27. data/lib/social_stream/linkser/engine.rb +7 -0
  28. data/lib/social_stream/linkser/version.rb +5 -0
  29. data/lib/social_stream/migrations/linkser.rb +9 -0
  30. data/social_stream-linkser.gemspec +26 -0
  31. data/spec/dummy/Rakefile +7 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  34. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/spec/dummy/config.ru +4 -0
  36. data/spec/dummy/config/application.rb +45 -0
  37. data/spec/dummy/config/boot.rb +10 -0
  38. data/spec/dummy/config/database.yml +22 -0
  39. data/spec/dummy/config/environment.rb +5 -0
  40. data/spec/dummy/config/environments/development.rb +25 -0
  41. data/spec/dummy/config/environments/production.rb +49 -0
  42. data/spec/dummy/config/environments/test.rb +37 -0
  43. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/dummy/config/initializers/devise.rb +176 -0
  45. data/spec/dummy/config/initializers/inflections.rb +10 -0
  46. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  47. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  48. data/spec/dummy/config/initializers/session_store.rb +8 -0
  49. data/spec/dummy/config/locales/en.yml +5 -0
  50. data/spec/dummy/config/navigation.rb +0 -0
  51. data/spec/dummy/config/relations.yml +39 -0
  52. data/spec/dummy/config/routes.rb +60 -0
  53. data/spec/dummy/db/.gitkeep +0 -0
  54. data/spec/dummy/documents/documents/000/000/001/original.pdf +157 -0
  55. data/spec/dummy/documents/documents/000/000/002/original.pdf +157 -0
  56. data/spec/dummy/documents/documents/000/000/003/original.pdf +157 -0
  57. data/spec/dummy/documents/documents/000/000/004/original.pdf +157 -0
  58. data/spec/dummy/documents/documents/000/000/005/original.pdf +157 -0
  59. data/spec/dummy/documents/documents/000/000/006/original.pdf +157 -0
  60. data/spec/dummy/documents/documents/000/000/007/original.pdf +157 -0
  61. data/spec/dummy/documents/documents/000/000/008/original.pdf +157 -0
  62. data/spec/dummy/documents/documents/000/000/009/original.pdf +157 -0
  63. data/spec/dummy/documents/documents/000/000/010/original.pdf +157 -0
  64. data/spec/dummy/documents/pictures/000/000/011/original.png +0 -0
  65. data/spec/dummy/documents/pictures/000/000/011/thumb.png +0 -0
  66. data/spec/dummy/documents/pictures/000/000/011/thumb0.png +0 -0
  67. data/spec/dummy/documents/pictures/000/000/012/original.png +0 -0
  68. data/spec/dummy/documents/pictures/000/000/012/thumb.png +0 -0
  69. data/spec/dummy/documents/pictures/000/000/012/thumb0.png +0 -0
  70. data/spec/dummy/documents/pictures/000/000/013/original.png +0 -0
  71. data/spec/dummy/documents/pictures/000/000/013/thumb.png +0 -0
  72. data/spec/dummy/documents/pictures/000/000/013/thumb0.png +0 -0
  73. data/spec/dummy/documents/pictures/000/000/014/original.png +0 -0
  74. data/spec/dummy/documents/pictures/000/000/014/thumb.png +0 -0
  75. data/spec/dummy/documents/pictures/000/000/014/thumb0.png +0 -0
  76. data/spec/dummy/documents/pictures/000/000/015/original.png +0 -0
  77. data/spec/dummy/documents/pictures/000/000/015/thumb.png +0 -0
  78. data/spec/dummy/documents/pictures/000/000/015/thumb0.png +0 -0
  79. data/spec/dummy/documents/pictures/000/000/016/original.png +0 -0
  80. data/spec/dummy/documents/pictures/000/000/016/thumb.png +0 -0
  81. data/spec/dummy/documents/pictures/000/000/016/thumb0.png +0 -0
  82. data/spec/dummy/documents/pictures/000/000/017/original.png +0 -0
  83. data/spec/dummy/documents/pictures/000/000/017/thumb.png +0 -0
  84. data/spec/dummy/documents/pictures/000/000/017/thumb0.png +0 -0
  85. data/spec/dummy/documents/pictures/000/000/018/original.png +0 -0
  86. data/spec/dummy/documents/pictures/000/000/018/thumb.png +0 -0
  87. data/spec/dummy/documents/pictures/000/000/018/thumb0.png +0 -0
  88. data/spec/dummy/documents/pictures/000/000/019/original.png +0 -0
  89. data/spec/dummy/documents/pictures/000/000/019/thumb.png +0 -0
  90. data/spec/dummy/documents/pictures/000/000/019/thumb0.png +0 -0
  91. data/spec/dummy/documents/pictures/000/000/020/original.png +0 -0
  92. data/spec/dummy/documents/pictures/000/000/020/thumb.png +0 -0
  93. data/spec/dummy/documents/pictures/000/000/020/thumb0.png +0 -0
  94. data/spec/dummy/public/404.html +26 -0
  95. data/spec/dummy/public/422.html +26 -0
  96. data/spec/dummy/public/500.html +26 -0
  97. data/spec/dummy/public/favicon.ico +0 -0
  98. data/spec/dummy/public/javascripts/application.js +2 -0
  99. data/spec/dummy/public/javascripts/controls.js +965 -0
  100. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  101. data/spec/dummy/public/javascripts/effects.js +1123 -0
  102. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  103. data/spec/dummy/public/javascripts/rails.js +191 -0
  104. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  105. data/spec/dummy/script/rails +6 -0
  106. data/spec/integration/navigation_spec.rb +9 -0
  107. data/spec/socialstream_linkser_spec.rb +7 -0
  108. data/spec/spec_helper.rb +48 -0
  109. data/spec/support/cancan.rb +1 -0
  110. data/spec/support/db.rb +8 -0
  111. data/spec/support/devise.rb +4 -0
  112. data/spec/support/mock.rb +4 -0
  113. data/vendor/assets/javascripts/jquery.jplayer.js +78 -0
  114. data/vendor/assets/stylesheets/jplayer.blue.monday.css +448 -0
  115. data/vendor/assets/stylesheets/jplayer.blue.monday.jpg +0 -0
  116. data/vendor/assets/stylesheets/jplayer.blue.monday.video.play.hover.png +0 -0
  117. data/vendor/assets/stylesheets/jplayer.blue.monday.video.play.png +0 -0
  118. data/vendor/assets/stylesheets/jquery.lightbox.css +101 -0
  119. data/vendor/assets/stylesheets/pbar-ani.gif +0 -0
  120. metadata +311 -0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ *.DS_Store
8
+ Gemfile.lock
9
+ .project
10
+ .idea/*
11
+ app/views/*/.tmp_*
12
+ **.*swp
13
+ .idea
14
+ spec/dummy/db/*sqlite3-journal
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'social_stream-base', :path => '../base'
4
+
5
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Universidad Politécnica de Madrid
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.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = Social Stream Linkser
2
+
3
+ Social Stream Linkser provides {Linkser}[https://github.com/ging/linkser/] support in
4
+ {Social Stream}[http://social-stream.dit.upm.es/], the core for building social
5
+ network websites.
6
+
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rdoc/task'
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task :default => :spec
12
+
13
+ Rake::RDocTask.new(:rdoc) do |rdoc|
14
+ rdoc.rdoc_dir = 'rdoc'
15
+ rdoc.title = 'SocialStream Linkser'
16
+ rdoc.options << '--line-numbers' << '--inline-source'
17
+ rdoc.rdoc_files.include('README.rdoc')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
20
+
21
+ # Modify this gem's tags
22
+ class Bundler::GemHelper
23
+ def version_tag
24
+ "linkser#{version}"
25
+ end
26
+ end
File without changes
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,41 @@
1
+ @import "colors";
2
+
3
+ #link_preview {
4
+ width: 510px;
5
+ height: 120px;
6
+ border: 1px solid $auxiliar-color;
7
+ margin: 5px auto;
8
+ }
9
+
10
+ #link_preview img.loading{
11
+ margin: auto;
12
+ margin-top: 40px;
13
+ }
14
+ .link {
15
+ position: relative;
16
+ padding: 10px;
17
+ }
18
+ .link .thumbnail, .link .thumbnail img{
19
+ float: left;
20
+ max-height: 100px;
21
+ max-width: 120px;
22
+ margin-right:10px;
23
+ }
24
+ .link .info{
25
+ float: left;
26
+ width: 360px;
27
+ text-align: left;
28
+ }
29
+ .activity_objects .link .info{
30
+ width: 320px;
31
+ }
32
+ .link .info .title{
33
+ font-weight: bold;
34
+ margin-bottom: 3px;
35
+ }
36
+ .link .info .url{
37
+ text-decoration: underline;
38
+ margin-bottom: 5px;
39
+ }
40
+ .link .info .description{
41
+ }
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree .
3
+ */
@@ -0,0 +1,3 @@
1
+ class LinksController < ApplicationController
2
+ include SocialStream::Controllers::Objects
3
+ end
@@ -0,0 +1,22 @@
1
+ class LinkserController < ApplicationController
2
+ def index
3
+ if params[:url].present?
4
+ url = params[:url]
5
+ o = Linkser.parse url, {:max_images => 1}
6
+ if o.is_a? Linkser::Objects::HTML
7
+ link = Link.new
8
+ link.title = o.title if o.title
9
+ link.description = o.description if o.description
10
+ link.url = o.last_url
11
+ if o.ogp and o.ogp.image
12
+ link.image = o.ogp.image
13
+ elsif o.images and o.images.first
14
+ link.image = o.images.first.url
15
+ end
16
+ render :partial => "links/link_preview", :locals => {:link => link}
17
+ return
18
+ end
19
+ end
20
+ render :text => I18n.t("link.errors.only_web")
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ class Link < ActiveRecord::Base
2
+ include SocialStream::Models::Object
3
+
4
+ validates_presence_of :url
5
+
6
+ attr_accessor :loaded
7
+
8
+ before_create :check_loaded
9
+
10
+ define_index do
11
+ indexes title
12
+ indexes description
13
+ indexes url
14
+
15
+ has created_at
16
+ end
17
+
18
+ def check_loaded
19
+ if !self.loaded.eql?"true" and self.title.nil? and self.description.nil? and self.image.nil?
20
+ o = Linkser.parse self.url, {:max_images => 1}
21
+ if o.is_a? Linkser::Objects::HTML
22
+ self.title = o.title if o.title
23
+ self.description = o.description if o.description
24
+ self.url = o.last_url
25
+ if o.ogp and o.ogp.image
26
+ self.image = o.ogp.image
27
+ elsif o.images and o.images.first
28
+ self.image = o.images.first.url
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,24 @@
1
+ <%= div_for link, :class => 'content_size' do %>
2
+ <% if link.image %>
3
+ <div class="thumbnail">
4
+ <%= link_to image_tag(link.image),link.url %>
5
+ </div>
6
+ <% end %>
7
+ <div class="info">
8
+ <% if link.title %>
9
+ <div class="title">
10
+ <%= link.title %>
11
+ </div>
12
+ <% end %>
13
+ <div class="url">
14
+ <%= auto_link(link.url) %>
15
+ </div>
16
+ <% if link.description %>
17
+ <div class="description">
18
+ <%= auto_link(link.description) %>
19
+ </div>
20
+ <% end %>
21
+ </div>
22
+ <% end %>
23
+
24
+ <br class="clearfloat">
@@ -0,0 +1,25 @@
1
+ <%= div_for link, :class => 'content_size' do %>
2
+ <% if link.image %>
3
+ <div class="thumbnail">
4
+ <%= image_tag(link.image)%>
5
+ <%= hidden_field_tag "link[image]", link.image %>
6
+ </div>
7
+ <% end %>
8
+ <div class="info">
9
+ <% if link.title %>
10
+ <div class="title">
11
+ <%= link.title %>
12
+ <%= hidden_field_tag "link[title]", link.title %>
13
+ </div>
14
+ <% end %>
15
+ <div class="url">
16
+ <%= auto_link(link.url) %>
17
+ </div>
18
+ <% if link.description %>
19
+ <div class="description">
20
+ <%= auto_link(link.description) %>
21
+ <%= hidden_field_tag "link[description]", link.description %>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <%= div_for link, :class => 'content_size' do %>
2
+ <%= simple_format link.title %>
3
+ <% end %>
4
+
@@ -0,0 +1,15 @@
1
+ //Display the new post
2
+ $("#wall").prepend("<%= escape_javascript(render @link.post_activity) %>");
3
+
4
+ setActivityPrivacyTooltips("<%= escape_javascript dom_id(@link.post_activity) %>");
5
+
6
+ unblock_all_forms();
7
+
8
+ $("#link_preview").hide();
9
+ $("#link_preview").html("");
10
+ $("#link_loaded").val(false);
11
+ $("#link_preview").html("");
12
+ $("#link_url").val("");
13
+
14
+
15
+
@@ -0,0 +1 @@
1
+ <%=render(:partial => 'objects/destroy') %>
@@ -0,0 +1,10 @@
1
+ <% content_for :javascript do %>
2
+ var message_hash = window.location.hash.match(/^.*activity_(\d+).*$/);
3
+ if (message_hash && message_hash > 0){
4
+ $.scrollTo('#activity_' + message_hash[1] ,1500,{axis:'y'});
5
+ }
6
+ <% end %>
7
+
8
+ <%= render :partial => 'objects/show',
9
+ :locals => { :object => @link } %>
10
+
@@ -0,0 +1,53 @@
1
+ <%= f.text_field :text, :id => "input_activities", :size => 85 %>
2
+ <%= hidden_field_tag "link[owner_id]", Actor.normalize_id(receiver) %>
3
+ <%= hidden_field_tag "link[url]" %>
4
+ <%= hidden_field_tag "link[loaded]", false %>
5
+ <div id="link_preview" style="display:none;"></div>
6
+
7
+ <%= javascript_tag do %>
8
+ $(function() {
9
+ $.preloadImages ("assets/loading.gif");
10
+ $("#input_activities").Watermark("<%= I18n.t('post.input') %>","#666");
11
+
12
+ var urlDetect = function(){
13
+ this.currentValue = $("#input_activities").val();
14
+ if(this.lastValue==null) this.lastValue = "";
15
+
16
+ var regexp = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/
17
+ if(regexp.test($("#input_activities").val())){
18
+ $("#link_url").val($("#input_activities").val());
19
+ $("#link_loaded").val(false);
20
+ $("#new_post").attr("action","<%= links_path %>");
21
+ if(this.currentValue!=this.lastValue){
22
+ $("#link_preview").html("<%= escape_javascript(image_tag('loading.gif', :class => :loading)) %>");
23
+ this.lastValue = this.currentValue;
24
+ var url = this.currentValue;
25
+ var urlDetect = this;
26
+ $.ajax({
27
+ type : "GET",
28
+ url : "<%= linkser_parse_url %>?url=" + url,
29
+ success : function(html) {
30
+ console.log("Peticion guay a " + url);
31
+ if ($("#input_activities").val()==url){ //Only show if input value is still the same
32
+ $("#link_preview").html(html);
33
+ $("#link_loaded").val(true);
34
+ }
35
+ },
36
+ error: function (xhr, ajaxOptions, thrownError){
37
+ $("#link_preview").html("<span class=\"loading\"><%= escape_javascript(t("link.errors.loading"))%> " + url + "</span>");
38
+ }
39
+ });
40
+ }
41
+ $("#link_preview").show();
42
+ }else{
43
+ $("#new_post").attr("action","<%= posts_path %>");
44
+ $("#link_preview").hide();
45
+ $("#link_preview").html("");
46
+ $("#link_url").val("");
47
+ }
48
+ }
49
+ $("#input_activities").change(urlDetect).keyup(urlDetect);
50
+
51
+ });
52
+
53
+ <% end %>
@@ -0,0 +1,14 @@
1
+ en:
2
+ linkser:
3
+ title: "Linkser"
4
+ link:
5
+ confirm_delete: "Delete link?"
6
+ errors:
7
+ loading: "Error loading"
8
+ only_webs: "Only webpages are supported"
9
+ form:
10
+ title: "Link"
11
+ input: "Write the web address"
12
+ name: "link"
13
+ one: "a link"
14
+ title: "Links"
@@ -0,0 +1,14 @@
1
+ es:
2
+ linkser:
3
+ title: "Linkser"
4
+ link:
5
+ confirm_delete: "¿Borrar enlace?"
6
+ errors:
7
+ loading: "Error cargando"
8
+ only_webs: "Solo puedes compartir págnas web"
9
+ form:
10
+ title: "Enlace"
11
+ input: "Escribe una dirección"
12
+ name: "enlace"
13
+ one: "una enlace"
14
+ title: "Enlaces"
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ match 'linkser_parse' => 'linkser#index', :as => :linkser_parse
3
+ end
@@ -0,0 +1,21 @@
1
+ class CreateSocialStreamLinkser < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "links", :force => true do |t|
4
+ t.integer "activity_object_id"
5
+ t.datetime "created_at"
6
+ t.datetime "updated_at"
7
+ t.string "url"
8
+ t.string "callback_url"
9
+ t.string "title"
10
+ t.string "image"
11
+ t.text "description"
12
+ end
13
+
14
+ add_index "links", "activity_object_id"
15
+ end
16
+
17
+ def self.down
18
+ remove_foreign_key "links", :name => "links_on_activity_object_id"
19
+ drop_table :links
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ class SocialStream::Linkser::InstallGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def create_migration_file
7
+ require 'rake'
8
+ Rails.application.load_tasks
9
+ Rake::Task['railties:install:migrations'].reenable
10
+ Rake::Task['social_stream_linkser_engine:install:migrations'].invoke
11
+ end
12
+
13
+ def require_javascripts
14
+ inject_into_file 'app/assets/javascripts/application.js',
15
+ "//= require social_stream-linkser\n",
16
+ :before => '//= require_tree .'
17
+ end
18
+
19
+ def require_stylesheets
20
+ inject_into_file 'app/assets/stylesheets/application.css',
21
+ " *= require social_stream-linkser\n",
22
+ :before => ' *= require_tree .'
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'social_stream-base'
2
+ require 'linkser'
3
+
4
+ module SocialStream
5
+ module Linkser
6
+ # Add :link to SocialStream.objects and SocialStream.activity_forms by default
7
+ # It can be configured by users at application's config/initializers/social_stream.rb
8
+ #%w(objects activity_forms).each do |m|
9
+ %w(objects).each do |m|
10
+ SocialStream.__send__(m).push(:link) unless SocialStream.__send__(m).include?(:link)
11
+ end
12
+
13
+ end
14
+ end
15
+
16
+ require 'social_stream/linkser/engine'