Commit ba1175295331ca4ca8b460a15b299170bbd5e7ca

Authored by Jose Pedro
Committed by Daniela Feitosa
1 parent 42889b9c

created lattes curriculum plugin

(ActionItem3102)

- placed the tab for lattes on the proffile and add the validation for it
- included lattes parser to the profile tab.
- informations of lattes curriculum formated and syncronized with database

Signed-off-by: Jose Pedro <1jpsneto@gmail.com>
Signed-off-by: Thiago Kairala <thiagor.kairala@gmail.com>
Signed-off-by: Ana Paula Vargas <anapaulavnoronha@gmail.com>
Signed-off-by: Leandro Veloso <leandrovelosorodrigues@gmail.com>
1 # encoding: UTF-8 1 # encoding: UTF-8
2 # This file is auto-generated from the current state of the database. Instead 2 # This file is auto-generated from the current state of the database. Instead
3 # of editing this file, please use the migrations feature of Active Record to 3 # of editing this file, please use the migrations feature of Active Record to
4 -# incrementally modify your database, and then regenerate this schema definition.  
5 # 4 #
6 # Note that this schema.rb definition is the authoritative source for your 5 # Note that this schema.rb definition is the authoritative source for your
7 # database schema. If you need to create the application database on another 6 # database schema. If you need to create the application database on another
plugins/lattes_curriculum/db/migrate/20140415223448_add_url_lattes_to_person.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class AddUrlLattesToPerson < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :profiles, :lattes_url, :string
  4 + end
  5 +
  6 + def self.down
  7 + remove_column :profiles, :lattes_url
  8 + end
  9 +end
plugins/lattes_curriculum/lib/ext/person.rb 0 → 100755
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +require_dependency 'person'
  2 +
  3 +class Person
  4 +
  5 + attr_accessible :lattes_url
  6 + validate :lattes_url_validate?
  7 +
  8 + def lattes_url_validate?
  9 + valid_url_start = 'http://lattes.cnpq.br/'
  10 + unless self.lattes_url =~ /http:\/\/lattes.cnpq.br\/\d+/
  11 + errors[:base] << "Sorry, the lattes url is not valid."
  12 + end
  13 + end
  14 +
  15 +end
0 \ No newline at end of file 16 \ No newline at end of file
plugins/lattes_curriculum/lib/html_parser.rb 0 → 100755
@@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
  1 +require 'rubygems'
  2 +require 'nokogiri'
  3 +require 'open-uri'
  4 +
  5 +Encoding.default_external = Encoding::UTF_8
  6 +Encoding.default_internal = Encoding::UTF_8
  7 +
  8 +class Html_parser
  9 + def get_html(lattes_link = "")
  10 + begin
  11 + page = Nokogiri::HTML(open(lattes_link), nil, "UTF-8")
  12 + page = page.css(".main-content").to_s()
  13 + page = remove_class_tooltip(page)
  14 + page = remove_img(page)
  15 + page = remove_select(page)
  16 + page = remove_footer(page)
  17 + page = remove_further_informations(page)
  18 + rescue
  19 + page = ""
  20 + end
  21 + end
  22 +
  23 + def remove_class_tooltip(string = "")
  24 + while string.include? 'class="tooltip"' do
  25 + string['class="tooltip"'] = 'class="link_not_to_mark"'
  26 + end
  27 + return string
  28 + end
  29 +
  30 + def remove_img(string = "")
  31 + fist_part_to_keep, *rest = string.split('<img')
  32 + second_part = rest.join(" ")
  33 + part_to_throw_away, *after_img = second_part.split('>',2)
  34 + string = fist_part_to_keep + after_img.join(" ")
  35 + end
  36 +
  37 + def remove_select(string = "")
  38 + while string.include? '<label' do
  39 + first_part_to_keep, *rest = string.split('<label')
  40 + second_part = rest.join(" ")
  41 + part_to_throw_away, *after_img = second_part.split('</select>')
  42 + string = first_part_to_keep + after_img.join(" ")
  43 + end
  44 + return string
  45 + end
  46 +
  47 + def remove_footer(string = "")
  48 + first_part_to_keep, *rest = string.split('<div class="rodape-cv">')
  49 + second_part = rest.join(" ")
  50 + part_to_throw_away, *after_img = second_part.split('Imprimir Curr&iacute;culo</a>')
  51 + string = first_part_to_keep + after_img.join(" ")
  52 + end
  53 +
  54 + def remove_further_informations(string = "")
  55 + first_part_to_keep, *rest = string.split('<a name="OutrasI')
  56 + second_part = rest.join(" ")
  57 + part_to_throw_away, *after_img = second_part.split('</div>',2)
  58 + string = first_part_to_keep + after_img.join(" ")
  59 + end
  60 +end
plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb 0 → 100755
@@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
  1 +class LattesCurriculumPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "LattesCurriculumPlugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin that imports the lattes curriculum into the users profiles")
  9 + end
  10 +
  11 + def js_files
  12 + ["singup_complement.js"]
  13 + end
  14 +
  15 + def stylesheet?
  16 + true
  17 + end
  18 +
  19 + def signup_extra_contents
  20 + lambda {
  21 + content_tag(:div, labelled_form_field(_('URL Lattes'), text_field(:profile_data, :lattes_url, :id => 'lattes_id_field')) +
  22 + content_tag(:small, _('The Lattes url is the link for your own curriculum so it\'ll be shown on your profile.'),
  23 + :class => 'signup-form', :id => 'lattes-id-balloon'), :id => 'signup-lattes-id')
  24 + }
  25 + end
  26 +
  27 + def profile_info_extra_contents
  28 + if context.profile.person?
  29 + lattes_url = context.profile.lattes_url
  30 + lambda {
  31 + content_tag('div', labelled_form_field(_('URL Lattes'), text_field_tag('profile_data[lattes_url]', lattes_url, :id => 'lattes_url_field', :disabled => false)) +
  32 + content_tag(:small, _('The url lattes is the link for your lattes curriculum.')))
  33 + }
  34 + end
  35 + end
  36 +
  37 + def profile_tabs
  38 + unless context.profile.lattes_url.nil?
  39 + href = context.profile.lattes_url
  40 + html_parser = Html_parser.new
  41 + {
  42 + :title => _("Lattes"),
  43 + :id => 'lattes_tab',
  44 + :content => lambda{html_parser.get_html(href)},
  45 + :start => false
  46 + }
  47 + end
  48 + end
  49 +end
plugins/lattes_curriculum/public/images/grey-bg.png 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +8950 4e47 0d0a 1a0a 0000 000d 4948 4452
  2 +0000 0009 0000 0027 0806 0000 00dd 3762
  3 +5600 0000 0173 5247 4200 aece 1ce9 0000
  4 +0006 624b 4744 00ff 00ff 00ff a0bd a793
  5 +0000 0009 7048 5973 0000 0dd7 0000 0dd7
  6 +0142 289b 7800 0000 0774 494d 4507 dc05
  7 +040f 1a01 22dc e3a3 0000 003b 4944 4154
  8 +38cb 635c 30bd f53f 0301 c0c4 4004 188c
  9 +8a58 18fe 13a3 8808 552c ff87 6810 101b
  10 +4eff 87af efa8 1704 c33e 1550 29b7 0c4a
  11 +dffd 1fa2 b905 009c 4210 1067 9fec 9d00
  12 +0000 0049 454e 44ae 4260 82
0 \ No newline at end of file 13 \ No newline at end of file
plugins/lattes_curriculum/public/singup_complement.js 0 → 100644
@@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
  1 +jQuery(function($) {
  2 + $(document).ready(function(){
  3 + $('#lattes_id_field').blur(function() {
  4 + var value = this.value
  5 +
  6 + })
  7 +
  8 + $('#lattes_id_field').focus(function() {
  9 + $('#lattes-id-balloon').fadeIn('slow')
  10 + })
  11 +
  12 + $('#lattes_id_field').blur(function() {
  13 + $('#lattes-id-balloon').fadeOut('slow')
  14 + })
  15 + })
  16 +})
0 \ No newline at end of file 17 \ No newline at end of file
plugins/lattes_curriculum/public/style.css 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +#signup-form label[for="lattes_id_field"],
  2 +{
  3 + display: block;
  4 +}
  5 +
  6 +#signup-form small#lattes-id-balloon
  7 +{
  8 + display: none;
  9 + width: 142px;
  10 + height: 69px;
  11 + color: #FFFFFF;
  12 + font-weight: bold;
  13 + font-size: 11px;
  14 + padding: 5px 10px 45px 10px;
  15 + margin: 0;
  16 + line-height: 1.5em;
  17 + background: transparent url(/images/gray-balloon.png) bottom center no-repeat;
  18 + position: absolute;
  19 + z-index: 2;
  20 + right: -150px;
  21 + top: -75px;
  22 +}
  23 +
  24 +#signup-form .formfield.checking {
  25 + border-color: transparent;
  26 + background-image: none;
  27 +}
  28 +
  29 +#signup-form small#lattes-id-balloon
  30 +{
  31 + top: -80px;
  32 +}
  33 +
  34 +#signup-form #signup-lattes-id
  35 +{
  36 + position: relative;
  37 +}
plugins/lattes_curriculum/test/unit/html_parser_test.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +require "test_helper"
  2 +
  3 +class HtmlParserTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @parser = Html_parser.new
  7 + end
  8 +
  9 + should 'be not nil the instance' do
  10 + assert_not_nil @parser
  11 + end
  12 +
  13 + should 'be not nil the return get_html' do
  14 + assert_not_nil @parser.get_html("http://lattes.cnpq.br/2193972715230641")
  15 + end
  16 +
  17 + should 'return a string the return get_html' do
  18 + assert_equal "", @parser.get_html()
  19 + end
  20 +
  21 +end
plugins/lattes_curriculum/test/unit/lattes_curriculum_test.rb 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +require "test_helper"
  2 +
  3 +class LattesCurriculumPluginTest < ActiveSupport::TestCase
  4 +
  5 + def setup
  6 + @plugin = LattesCurriculumPlugin.new
  7 + end
  8 +
  9 + should 'be a noosfero plugin' do
  10 + assert_kind_of Noosfero::Plugin, @plugin
  11 + end
  12 +
  13 + should 'have name' do
  14 + assert_equal 'LattesCurriculumPlugin', LattesCurriculumPlugin.plugin_name
  15 + end
  16 +
  17 + should 'have description' do
  18 + assert_equal _('A plugin that imports the lattes curriculum into the users profiles'), LattesCurriculumPlugin.plugin_description
  19 + end
  20 +
  21 + should 'have stylesheet' do
  22 + assert @plugin.stylesheet?
  23 + end
  24 +
  25 +end