talia_core 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/VERSION.yml +1 -1
  2. data/generators/generator_helpers.rb +35 -2
  3. data/generators/talia_admin/talia_admin_generator.rb +6 -0
  4. data/generators/talia_admin/templates/controllers/admin/background_controller.rb +2 -0
  5. data/generators/talia_admin/templates/controllers/admin/roles_controller.rb +8 -0
  6. data/generators/talia_admin/templates/controllers/admin/sources_controller.rb +2 -64
  7. data/generators/talia_admin/templates/controllers/admin/users_controller.rb +3 -41
  8. data/generators/talia_admin/templates/controllers/admin_controller.rb +1 -1
  9. data/generators/talia_admin/templates/helpers/admin/roles_helper.rb +2 -0
  10. data/generators/talia_admin/templates/helpers/admin/users_helper.rb +9 -0
  11. data/generators/talia_admin/templates/helpers/admin_helper.rb +19 -0
  12. data/generators/{talia_base → talia_admin}/templates/migrations/populate_users.rb +5 -2
  13. data/generators/talia_admin/templates/models/role.rb +3 -0
  14. data/generators/talia_admin/templates/public/stylesheets/backend.css +1 -4
  15. data/generators/talia_admin/templates/views/admin/index.html.erb +3 -3
  16. data/generators/talia_admin/templates/views/admin/sources/_show.html.erb +13 -0
  17. data/generators/talia_admin/templates/views/layouts/admin.html.erb +5 -5
  18. data/generators/talia_base/talia_base_generator.rb +11 -18
  19. data/generators/talia_base/templates/README +15 -0
  20. data/generators/talia_base/templates/app/controllers/sources_controller.rb +125 -7
  21. data/generators/talia_base/templates/app/helpers/sources_helper.rb +19 -35
  22. data/generators/talia_base/templates/app/views/sources/index.html.erb +12 -1
  23. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/default.html.erb +21 -0
  24. data/generators/talia_base/templates/app/views/sources/semantic_templates/default/province.html.erb +19 -0
  25. data/generators/talia_base/templates/config/routes.rb +24 -4
  26. data/generators/talia_base/templates/script/setup_talia_backend +35 -0
  27. data/lib/loader_helper.rb +8 -1
  28. data/lib/talia_core/active_source.rb +9 -6
  29. data/lib/talia_core/active_source_parts/class_methods.rb +2 -1
  30. data/lib/talia_core/active_source_parts/predicate_handler.rb +12 -0
  31. data/lib/talia_core/active_source_parts/rdf.rb +1 -1
  32. data/lib/talia_core/data_types/iip_loader.rb +2 -0
  33. data/lib/talia_core/dc_resource.rb +1 -1
  34. data/lib/talia_core/initializer.rb +2 -0
  35. data/lib/talia_core/semantic_relation.rb +1 -1
  36. data/lib/talia_util/rake_tasks.rb +2 -2
  37. data/lib/talia_util/util.rb +1 -1
  38. data/test/talia_core/active_source_predicate_test.rb +2 -6
  39. data/test/talia_core/active_source_rdf_test.rb +9 -5
  40. data/test/talia_core/active_source_test.rb +50 -44
  41. data/test/talia_core/data_types/data_loader_test.rb +2 -2
  42. data/test/talia_core/data_types/data_record_test.rb +1 -1
  43. data/test/talia_core/data_types/file_record_test.rb +4 -3
  44. data/test/talia_core/data_types/iip_data_test.rb +2 -2
  45. data/test/talia_core/data_types/image_data_test.rb +1 -1
  46. data/test/talia_core/data_types/pdf_data_test.rb +1 -1
  47. data/test/talia_core/data_types/xml_data_test.rb +3 -2
  48. data/test/talia_core/initializer_test.rb +1 -1
  49. data/test/talia_core/ordered_source_test.rb +1 -5
  50. data/test/talia_core/rdf_resource_test.rb +1 -5
  51. data/test/talia_core/semantic_collection_item_test.rb +3 -7
  52. data/test/talia_core/source_test.rb +7 -12
  53. data/test/talia_core/workflow/publication_workflow_test.rb +36 -23
  54. data/test/talia_util/import_job_helper_test.rb +1 -5
  55. data/test/test_helper.rb +18 -5
  56. metadata +11 -52
  57. data/generators/talia_admin/templates/test/fixtures/users.yml +0 -32
  58. data/generators/talia_admin/templates/test/unit/user_test.rb +0 -134
  59. data/generators/talia_admin/templates/views/admin/sources/_data.html.erb +0 -6
  60. data/generators/talia_admin/templates/views/admin/sources/_data_form.html.erb +0 -15
  61. data/generators/talia_admin/templates/views/admin/sources/_form.html.erb +0 -7
  62. data/generators/talia_admin/templates/views/admin/sources/_list.html.erb +0 -3
  63. data/generators/talia_admin/templates/views/admin/sources/_notice.html.erb +0 -1
  64. data/generators/talia_admin/templates/views/admin/sources/_predicate.html.erb +0 -22
  65. data/generators/talia_admin/templates/views/admin/sources/_predicates.html.erb +0 -15
  66. data/generators/talia_admin/templates/views/admin/sources/_sources.html.erb +0 -17
  67. data/generators/talia_admin/templates/views/admin/sources/_upload.html.erb +0 -6
  68. data/generators/talia_admin/templates/views/admin/sources/edit.html.erb +0 -6
  69. data/generators/talia_admin/templates/views/admin/sources/index.html.erb +0 -5
  70. data/generators/talia_admin/templates/views/admin/users/_form.html.erb +0 -10
  71. data/generators/talia_admin/templates/views/admin/users/_form_roles.html.erb +0 -8
  72. data/generators/talia_admin/templates/views/admin/users/edit.html.erb +0 -12
  73. data/generators/talia_admin/templates/views/admin/users/index.html.erb +0 -22
  74. data/generators/talia_admin/templates/views/admin/users/new.html.erb +0 -5
  75. data/generators/talia_admin/templates/views/admin/users/show.html.erb +0 -6
  76. data/generators/talia_base/templates/app/controllers/sessions_controller.rb +0 -90
  77. data/generators/talia_base/templates/app/controllers/source_data/show.html.erb +0 -2
  78. data/generators/talia_base/templates/app/helpers/source_data/show.html.erb +0 -2
  79. data/generators/talia_base/templates/app/views/sessions/new.html.erb +0 -33
  80. data/generators/talia_base/templates/migrations/create_open_id.rb +0 -26
  81. data/generators/talia_base/templates/migrations/create_roles.rb +0 -20
  82. data/generators/talia_base/templates/migrations/create_sessions.rb +0 -16
  83. data/generators/talia_base/templates/migrations/create_users.rb +0 -20
  84. data/lib/role.rb +0 -12
  85. data/lib/talia_cl/command_line.rb +0 -39
  86. data/lib/talia_cl/commands/standalone/cl_options.rb +0 -9
  87. data/lib/talia_cl/commands/standalone/standalone_generate.rb +0 -75
  88. data/lib/talia_cl/commands/standalone.rb +0 -25
  89. data/lib/talia_cl/commands/talia_console/cl_options.rb +0 -55
  90. data/lib/talia_cl/commands/talia_console/console_commands.rb +0 -37
  91. data/lib/talia_cl/commands/talia_console/talia_commands.rb +0 -131
  92. data/lib/talia_cl/commands/talia_console.rb +0 -47
  93. data/lib/talia_cl/core_commands.rb +0 -11
  94. data/lib/talia_cl.rb +0 -47
  95. data/lib/user.rb +0 -116
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 4
3
3
  :major: 0
4
- :patch: 2
4
+ :patch: 3
@@ -19,6 +19,26 @@ module GeneratorHelpers
19
19
  m.migration_template "migrations/#{template_name}", "db/migrate", :migration_file_name => template_name.gsub(/\.rb\Z/, '')
20
20
  end
21
21
 
22
+ # This is more of a quick hack, but the functionality requires extra plugins
23
+ # and by installing them from the generator everything can be done with
24
+ # one single command
25
+ def install_plugin(plugin_url)
26
+ system("#{ruby_bin} #{plugin_script} install #{plugin_url}")
27
+ end
28
+
29
+ # Path to the plugin (installer) script
30
+ def plugin_script
31
+ @plugin_script ||= File.join(RAILS_ROOT, 'script', 'plugin')
32
+ end
33
+
34
+ # Path to the ruby binary that we're currently using
35
+ def ruby_bin
36
+ @ruby_bin ||= begin
37
+ c = ::Config::CONFIG
38
+ File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
39
+ end
40
+ end
41
+
22
42
  end
23
43
 
24
44
  # This monkeypatches a problem in the generator that causes it to have
@@ -32,15 +52,28 @@ module Rails
32
52
 
33
53
  alias :orig_migration_string :next_migration_string
34
54
 
55
+ def migration_xtime
56
+ @migration_xtime ||= Time.now
57
+ end
58
+
59
+ def migration_time
60
+ @migration_time ||= migration_xtime.utc.strftime('%Y%m%d%H%M')
61
+ end
62
+
35
63
  def migration_count
36
- @m_count ||= 0
64
+ @m_count ||= begin
65
+ Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/#{migration_time}*.rb").inject(migration_xtime.sec) do |max, file|
66
+ n = File.basename(file)[12..13].to_i
67
+ (n > max) ? n : max
68
+ end
69
+ end
37
70
  @m_count += 1
38
71
  @m_count
39
72
  end
40
73
 
41
74
  def next_migration_string(padding = 3)
42
75
  return orig_migration_string(padding) unless(ActiveRecord::Base.timestamped_migrations)
43
- (Time.now.utc.strftime("%Y%m%d%H%M") + ("%.2d" % migration_count))
76
+ migration_time + ("%.2d" % migration_count)
44
77
  end
45
78
 
46
79
  end
@@ -13,6 +13,12 @@ class TaliaAdminGenerator < Rails::Generator::Base
13
13
  files_in m, 'controllers', 'app/'
14
14
  files_in m, 'public'
15
15
  files_in m, 'test'
16
+
17
+ m.directory 'app/models'
18
+ m.file 'models/role.rb', 'app/models/role.rb', :collision => :force
19
+
20
+ m.directory 'db/migrate'
21
+ make_migration m, "populate_users.rb"
16
22
  end
17
23
  end
18
24
 
@@ -1,3 +1,5 @@
1
+ require 'bj'
2
+
1
3
  class Admin::BackgroundController < ApplicationController
2
4
  layout 'admin', :except => [:update_progress]
3
5
  require_role 'admin'
@@ -0,0 +1,8 @@
1
+ class Admin::RolesController < ApplicationController
2
+ require_role 'admin'
3
+ layout 'admin'
4
+
5
+ active_scaffold :role do |config|
6
+ # config.columns[:users].association.reverse = :user
7
+ end
8
+ end
@@ -1,71 +1,9 @@
1
- require 'paginator'
2
-
3
1
  class Admin::SourcesController < ApplicationController
4
- include TaliaCore
5
2
  require_role 'admin'
6
3
  layout 'admin'
7
- cache_sweeper :av_media_sweeper, :only => :update
8
4
 
9
- # GET /admin/sources
10
- # GET /admin/sources.xml
11
- def index
12
- @sources = TaliaCore::Source.paginate :page => params[:page], :per_page => 10
13
-
14
- respond_to do |format|
15
- format.html # index.html.erb
16
- format.xml { render :xml => @sources }
17
- format.js do
18
- render :update do |page|
19
- page.replace_html 'sources', :partial => 'sources'
20
- end
21
- end
22
- end
23
- end
24
-
25
- # GET /admin/sources/1/edit
26
- def edit
27
- @source = TaliaCore::Source.find_by_partial_uri(params[:id])
5
+ active_scaffold 'TaliaCore::ActiveSource' do |config|
6
+ config.columns = [:uri, :type]
28
7
  end
29
8
 
30
- # PUT /admin/sources/1
31
- # PUT /admin/sources/1.xml
32
- def update
33
- @source = TaliaCore::Source.find_by_id(params[:id])
34
-
35
- respond_to do |format|
36
- if @source.update_attributes(params[:source])
37
- flash[:notice] = 'Source was successfully updated.'
38
- format.html { redirect_to :action => "index" }
39
- format.xml { head :ok }
40
- else
41
- format.html { render :action => "edit" }
42
- format.xml { render :xml => @source.errors, :status => :unprocessable_entity }
43
- end
44
- end
45
- end
46
-
47
- # GET /admin/sources/data/1
48
- def data
49
- # We need to specify the clause, because of Source#find overwrite the
50
- # default behavior.
51
- @source = TaliaCore::Source.find_by_id(params[:id])
52
-
53
- respond_to do |format|
54
- format.js do
55
- render :update do |page|
56
- page.replace_html 'list', :partial => 'list'
57
- page.insert_html :top, 'data', :partial => 'notice', :locals => { :text => 'Your file has been saved.'}
58
- page[:data_notice].visual_effect :highlight
59
- page[:data_notice].visual_effect :fade, :duration => 3
60
- page.delay(3.1) { page.remove :data_notice }
61
- end
62
- end
63
- end
64
- end
65
-
66
- # GET /admin/sources/auto_complete_for_source/aaa
67
- def auto_complete_for_source
68
- @items = TaliaCore::Source.find_by_uri_token(params[:source][:predicates_attributes].first[:titleized])
69
- render :inline => "<%= auto_complete_result @items, 'titleized' %>"
70
- end
71
9
  end
@@ -1,48 +1,10 @@
1
1
  class Admin::UsersController < ApplicationController
2
2
  require_role 'admin'
3
3
  layout 'admin'
4
- PER_PAGE = 10
5
-
6
- def index
7
- @users = User.paginate(:page => params[:page], :per_page => PER_PAGE)
8
- end
9
-
10
- def show
11
- @user = User.find(params[:id])
12
- end
13
-
14
- def new
15
- @user = User.new
16
- end
17
4
 
18
- def create
19
- @user = User.new(params[:user])
20
-
21
- if @user.save
22
- flash[:notice] = "User was successfully created."
23
- redirect_to :action => 'show', :id => @user
24
- else
25
- render :action => 'new'
26
- end
5
+ active_scaffold :user do |config|
6
+ config.columns = [:login, :name, :email, :password, :password_confirmation, :roles]
7
+ list.columns.exclude :password, :password_confirmation
27
8
  end
28
9
 
29
- def edit
30
- @user = User.find(params[:id])
31
- end
32
-
33
- def update
34
- @user = User.find(params[:id])
35
-
36
- if @user.update_attributes(params[:user])
37
- flash[:notice] = "User was successfully updated."
38
- redirect_to :action => 'show', :id => @user
39
- else
40
- render :action => 'edit'
41
- end
42
- end
43
-
44
- def destroy
45
- User.find(params[:id]).destroy
46
- redirect_to :action => 'index'
47
- end
48
10
  end
@@ -2,6 +2,6 @@ class AdminController < ApplicationController
2
2
  require_role 'admin'
3
3
 
4
4
  def index
5
- @links = %w(users custom_templates translations) # sources removed as non-working
6
5
  end
6
+
7
7
  end
@@ -0,0 +1,2 @@
1
+ module Admin::RolesHelper
2
+ end
@@ -1,2 +1,11 @@
1
1
  module Admin::UsersHelper
2
+
3
+ def password_form_column(record, field_name)
4
+ password_field_tag field_name, record.password
5
+ end
6
+
7
+ def password_confirmation_form_column(record, field_name)
8
+ password_field_tag field_name, record.password_confirmation
9
+ end
10
+
2
11
  end
@@ -8,4 +8,23 @@ module AdminHelper
8
8
  ["Print Page", "javascript:print();"]
9
9
  ] )
10
10
  end
11
+
12
+ # Returns the title for the whole page. This returns the value
13
+ # set in the controller, or a default value
14
+ def page_title
15
+ @page_title || TaliaCore::SITE_NAME
16
+ end
17
+
18
+ # Show each <tt>flash</tt> status (<tt>:notice</tt>, <tt>:error</tt>) only if it's present.
19
+ def show_flash
20
+ [:notice, :error].collect do |status|
21
+ %(<div id="#{status}">#{flash[status]}</div>) unless flash[status].nil?
22
+ end
23
+ end
24
+
25
+ # Defines the pages that are visible in the menu
26
+ def active_pages
27
+ %w(users background sources) # translations not working at the moment, templates not ready for generic use
28
+ end
29
+
11
30
  end
@@ -1,9 +1,12 @@
1
1
  class PopulateUsers < ActiveRecord::Migration
2
2
  def self.up
3
3
  admins = Role.create :name => 'admin'
4
- Role.create :name => 'user'
5
- admin = User.create :login => 'admin', :email => 'admin@admins.foob', :password => 'admin', :password_confirmation => 'admin'
4
+ users = Role.create :name => 'user'
5
+ admin = User.create :login => 'admin', :email => 'admin@admins.com', :password => 'adminadmin', :password_confirmation => 'adminadmin'
6
6
  admin.roles << admins
7
+ admins.save!
8
+ users.save!
9
+ admin.save!
7
10
  end
8
11
 
9
12
  def self.down
@@ -0,0 +1,3 @@
1
+ class Role < ActiveRecord::Base
2
+ has_and_belongs_to_many :users
3
+ end
@@ -255,7 +255,7 @@ div.main_menu_box a{
255
255
  float: left;
256
256
  text-align:center;
257
257
  padding: 0 20px;
258
-
258
+ margin-right: 30px;
259
259
  font-size: 20px;
260
260
  font-family:Georgia, "Times New Roman", Times, serif;
261
261
  }
@@ -267,14 +267,11 @@ div.main_menu_box a:hover{
267
267
  }
268
268
 
269
269
  #users_access a{
270
- margin-right: 30px;
271
270
  }
272
271
  #sources_access a{
273
- margin-right: 30px;
274
272
  }
275
273
 
276
274
  #custom_templates_access a{
277
- margin-right: 30px;
278
275
  }
279
276
 
280
277
  #translations_access a{
@@ -1,5 +1,5 @@
1
- <% for link in @links %>
2
- <div id="<%= link %>_access" class="main_menu_box">
3
- <%= link_to h(link.titleize), :controller => "admin/#{h(link)}" %>
1
+ <% for admin_page in active_pages %>
2
+ <div id="<%= admin_page %>_access" class="main_menu_box">
3
+ <%= link_to h(admin_page.titleize), :controller => "admin/#{h(admin_page)}" %>
4
4
  </div>
5
5
  <% end %>
@@ -0,0 +1,13 @@
1
+ <% @source = TaliaCore::ActiveSource.find(:first, :conditions => { :id => params[:id] }, :prefetch_relations => true) %>
2
+
3
+ <h1><%= @source[N::DCNS.title].first || N::URI.new(@source).to_name_s %></h1>
4
+ <% for pred in @source.direct_predicates %>
5
+ <h2><%= N::URI.new(pred).to_name_s %></h2>
6
+ <ul>
7
+ <% for prop in @source[pred] %>
8
+ <li>
9
+ <%= prop.is_a?(TaliaCore::ActiveSource) ? link_to(N::URI.new(prop.uri).to_name_s, prop.uri.to_s) : prop.to_s %>
10
+ </li>
11
+ <% end %>
12
+ </ul>
13
+ <% end %>
@@ -32,11 +32,11 @@
32
32
 
33
33
  <div id="menu">
34
34
  <ul>
35
- <li><%= link_to('Home', '/') %>
36
- <li><%= link_to('Users', :controller => 'admin/users') %></li>
37
- <li><%= link_to('Translations', :controller => 'admin/translations') %></li>
38
- <li><%= link_to('Templates', :controller => 'admin/custom_templates')%>
39
- <li><%= link_to('Logout', '/logout') %></li>
35
+ <li><%= link_to('Home', '/') %>
36
+ <% for admin_page in active_pages %>
37
+ <li><%= link_to(admin_page.titleize, :controller => "admin/#{admin_page}")%></li>
38
+ <% end %>
39
+ <li><%= link_to('Logout', :controller => 'sessions', :action => 'destroy') %></li>
40
40
  </ul>
41
41
  </div>
42
42
 
@@ -4,14 +4,9 @@ class TaliaBaseGenerator < Rails::Generator::Base
4
4
 
5
5
  include GeneratorHelpers
6
6
 
7
- def manifest
8
- puts "Trying to install the plugins before generation"
9
- plugin_script = File.join(RAILS_ROOT, 'script', 'plugin')
10
- c = ::Config::CONFIG
11
- ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
12
-
13
- system("#{ruby} #{plugin_script} install git://github.com/activescaffold/active_scaffold.git")
14
- system("#{ruby} #{plugin_script} install git://github.com/timcharper/role_requirement.git")
7
+ def manifest
8
+ install_plugin("git://github.com/activescaffold/active_scaffold.git")
9
+ install_plugin("git://github.com/timcharper/role_requirement.git")
15
10
 
16
11
  record do |m|
17
12
  # Some initialization stuff
@@ -24,6 +19,7 @@ class TaliaBaseGenerator < Rails::Generator::Base
24
19
  m.directory 'script'
25
20
  m.file 'script/configure_talia', 'script/configure_talia', :shebang => DEFAULT_SHEBANG, :chmod => 0755
26
21
  m.file 'script/prepare_images', 'script/prepare_images', :shebang => DEFAULT_SHEBANG, :chmod => 0755
22
+ m.file 'script/setup_talia_backend', 'script/setup_talia_backend', :shebang => DEFAULT_SHEBANG, :chmod => 0755
27
23
 
28
24
  # The whole app shebang of files
29
25
  files_in m, 'app'
@@ -31,14 +27,15 @@ class TaliaBaseGenerator < Rails::Generator::Base
31
27
  # The default ontologies
32
28
  files_in m, 'ontologies'
33
29
 
30
+ # Set up the rake tasks, only if we come from a gem
31
+ if(Gem.source_index.find_name('talia_core').first)
32
+ m.directory 'lib/tasks'
33
+ m.file 'tasks/talia_core.rk', 'lib/tasks/talia_core.rake'
34
+ end
35
+
34
36
  # Add the migrations
35
37
  m.directory 'db/migrate'
36
38
  m.file "migrations/constraint_migration.rb", "db/migrate/constraint_migration.rb"
37
- make_migration m, "create_sessions.rb"
38
- make_migration m, "create_users.rb"
39
- make_migration m, "create_open_id.rb"
40
- make_migration m, "create_roles.rb"
41
- make_migration m, "populate_users.rb"
42
39
  make_migration m, "create_active_sources.rb"
43
40
  make_migration m, "create_semantic_relations.rb"
44
41
  make_migration m, "create_semantic_properties.rb"
@@ -49,11 +46,7 @@ class TaliaBaseGenerator < Rails::Generator::Base
49
46
  make_migration m, "create_progress_jobs.rb"
50
47
  make_migration m, "bj_migration.rb"
51
48
 
52
- # Set up the rake tasks, only if we come from a gem
53
- if(Gem.source_index.find_name('talia_core').first)
54
- m.directory 'lib/tasks'
55
- m.file 'tasks/talia_core.rk', 'lib/tasks/talia_core.rake'
56
- end
49
+ m.readme 'README'
57
50
  end
58
51
  end
59
52
 
@@ -0,0 +1,15 @@
1
+
2
+ The Core classes were successfully installed. You can now run
3
+
4
+ script/configure_talia
5
+
6
+ to set up the main configuration for database and RDF store. You can also
7
+ create the configuration by hand.
8
+
9
+ WARNING: Talia can create HUGE loge files, depending on the level. It is
10
+ highly recommended that you at least add something like this to your
11
+ environment.rb file:
12
+
13
+ config.logger = Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log", 3, 104857600)
14
+
15
+ After you are set up, you can start importing data.
@@ -1,14 +1,25 @@
1
1
  class SourcesController < ApplicationController
2
2
  include TaliaCore
3
3
 
4
- before_filter :setup_format
5
-
4
+ before_filter :setup_format, :except => [ 'dispatch', 'index' ]
5
+
6
6
  PER_PAGE = 10
7
7
 
8
8
  # GET /sources
9
9
  # GET /sources.xml
10
10
  def index
11
-
11
+ @rdf_types ||= self.class.source_types
12
+
13
+ conditions = if(filter = params[:filter])
14
+ { :find_through => [N::RDF.type, N::URI.make_uri(filter, '+')] }
15
+ else
16
+ {}
17
+ end
18
+ if(will_paginate?)
19
+ @sources = TaliaCore::ActiveSource.paginate(conditions.merge(:page => params[:page]))
20
+ else
21
+ @sources = TaliaCore::ActiveSource.find(:all, conditions)
22
+ end
12
23
  end
13
24
 
14
25
  # GET /sources/1
@@ -43,9 +54,26 @@ class SourcesController < ApplicationController
43
54
  render :text => predicates, :status => status
44
55
  end
45
56
 
46
- private
47
-
57
+ # Semantic dispatch. This will try to auto-handle URLs that are not otherwise
58
+ # caught and see if a source exists. If the source exists, the system will
59
+ # try to figure out how to render it. In this case, all relations on the source are
60
+ # automaticaly prefetched when it's loaded.
61
+ def dispatch
62
+ @source = TaliaCore::ActiveSource.find(params[:dispatch_uri], :prefetch_relations => true)
63
+ @types = @source.types
64
+ @types.each do |type|
65
+ caller = type.to_name_s('_')
66
+ self.send(caller) if(self.respond_to?(caller))
67
+ end
68
+ respond_to do |format|
69
+ format.xml { render :text => @source.to_xml }
70
+ format.rdf { render :text => @source.to_rdf }
71
+ format.html { render :action => template_for(@source) }
72
+ end
73
+ end
48
74
 
75
+ private
76
+
49
77
  # Hack around routing limitation: We use the @ instead of the dot as a delimiter
50
78
  def setup_format
51
79
  split_id = params[:id].split('@')
@@ -54,9 +82,99 @@ class SourcesController < ApplicationController
54
82
  params[:format] = (split_id.size > 1) ? split_id.last : 'html'
55
83
  end
56
84
 
85
+ private
86
+
87
+ # Indicates if pagination is available.
88
+ def will_paginate?
89
+ return @will_paginate if(@will_paginate != nil)
90
+ return true if(defined?(WillPaginate))
91
+ begin
92
+ require 'rubygems'
93
+ require 'will_paginate'
94
+ @will_paginate = true
95
+ rescue MissingSourceFile
96
+ logger.warn('will_paginate cannot be found, pagination is not available')
97
+ @will_paginate = false
98
+ end
99
+ @will_paginate
100
+ end
101
+
102
+ # Returns the first matching template for the given source.
103
+ #
104
+ # * If the source has RDF types, it will try to find the first template
105
+ # that matches one of the RDF types. If one is found is it returned.
106
+ # * Otherwise, it will look for a default template matching the source's
107
+ # runtime class.
108
+ # * If no other template is found, this will return the default template name
109
+ def template_for(source)
110
+ source.types.each do |type|
111
+ if(template = template_map[type.uri.to_s])
112
+ return template
113
+ end
114
+ end
115
+ template = template_map[source.class.name.demodulize]
116
+ template ? template : "semantic_templates/default/default"
117
+ end
118
+
119
+ def template_map
120
+ self.class.template_map
121
+ end
122
+
123
+ class << self
124
+
125
+ def template_map
126
+ return @template_map if(@template_map && (ActiveSupport::Dependencies.mechanism != :require))
127
+ @template_map = {}
128
+ Dir["#{template_path}/*"].each do |dir|
129
+ next unless(File.directory?(dir) && File.basename(dir) != 'default')
130
+ map_templates_in(dir)
131
+ end
132
+ map_default_templates
133
+ @template_map
134
+ end
135
+
136
+ def template_path
137
+ @template_path ||= File.join(RAILS_ROOT, 'app', 'views', 'sources', 'semantic_templates')
138
+ end
139
+
140
+ def source_types
141
+ return @source_types if(@source_types)
142
+ @source_types = Query.new(N::URI).select(:type).distinct.where(:source, N::RDF.type, :type).execute
143
+ @source_types
144
+ end
145
+
146
+ private
147
+
148
+ # Creates a hash that can be used for looking up the correct semantic
149
+ # template for a source. This scans the template directory and connects
150
+ # the templates to the right RDF types
151
+ def map_templates_in(dir)
152
+ namespace = N::Namespace[File.basename(dir)]
153
+ namsp_object = N::Namespace[namespace]
154
+ TaliaCore.logger.warn("WARNING: Template files in #{dir} are never used, no namespace: #{namespace}.") unless(namesp_object)
155
+ return unless(namesp_object)
156
+ Dir["#{dir}/*"].each do |template|
157
+ next unless(File.file?(template))
158
+ template = template_basename(template)
159
+ @template_map[(namsp_object + template).to_s] = "semantic_templates/#{namespace}/#{template}"
160
+ end
161
+ end
57
162
 
58
- def get_uri
59
-
163
+ # Map the "default" templates to runtime types
164
+ def map_default_templates
165
+ Dir["#{template_path}/default/*"].each do |templ|
166
+ templ_name = template_basename(templ)
167
+ next unless(File.file?(templ) && templ_name != 'default' )
168
+ @template_map[templ_name.camelize] = "semantic_templates/default/#{templ_name}"
169
+ end
170
+ end
171
+
172
+ # Get the "basename" of a template
173
+ def template_basename(template_file)
174
+ base = File.basename(template_file)
175
+ base.gsub(/\..*\Z/, '')
176
+ end
177
+
60
178
  end
61
179
 
62
180
  end
@@ -1,39 +1,23 @@
1
1
  module SourcesHelper
2
-
3
- # Renders the data
4
- def render_source_data
5
- result = ""
6
- if(@source.data_records.size > 0)
7
- @source.data_records.each do |data_record|
8
- case(data_record.mime_type)
9
- when 'text/html'
10
- result += "<h3>HTML Data: #{data_record.location}</h3>"
11
- result += "<div>"
12
- result += widget(:html_data, :data => data_record)
13
- result += "</div>"
14
- when 'text/xml'
15
- result += "<pre><code>"
16
- result += data_record.get_escaped_content_string
17
- result += "</code></pre>"
18
- when 'text/plain'
19
- result += "<h3>Plain Text Data: #{data_record.location}</h3>"
20
- result += "<pre> #{data_record.all_text} </pre>"
21
- else
22
- result += "<h3>Found data object of type #{data_record.class} (#{data_record.mime_type}): #{data_record.location}</h3>"
23
- end
24
- end
25
- else
26
- result ="<h3>Sorry mate, no data objects here</h3>"
27
- end
28
-
29
- result
2
+
3
+ # Link to the index
4
+ def index_link
5
+ link_to 'index', :action => 'index'
30
6
  end
31
-
32
- def source_toolbar
33
- widget(:toolbar, :buttons => [
34
- ["Lucca", {:action => 'show', :id => 'Lucca'}],
35
- ["All", {:action => 'index'} ],
36
- ["Print Page", "javascript:print();"]
37
- ] )
7
+
8
+ # Checks if the current filter points to the given type
9
+ def current_filter?(ctype)
10
+ (ctype.to_name_s('+') == params[:filter])
38
11
  end
12
+
13
+ # Links to filter for the given type
14
+ def filter_link_for(ctype)
15
+ link_to ctype.to_name_s, :action => 'index', :filter => ctype.to_name_s('+')
16
+ end
17
+
18
+ # Gets the title for a source
19
+ def title_for(source)
20
+ (source[N::DCNS.title].first || N::URI.new(source.uri).local_part)
21
+ end
22
+
39
23
  end
@@ -1,2 +1,13 @@
1
1
  <h1>Sources found: <%= @sources.total_entries %></h1>
2
- <%= widget(:grouped_list, :id => 'main_list', :group_property => :type, :group_values => @types, :group_increment => @group_increment) %>
2
+
3
+ <div class="tags">
4
+ <% for type in @rdf_types %>
5
+ <span class="<%= current_filter?(type) ? 'tag_selected' : 'tag' %>"><%= filter_link_for(type) %></span>
6
+ <% end %>
7
+ </div>
8
+
9
+ <% for source in @sources %>
10
+ <p><%= link_to title_for(source), source.uri.to_s %> (<%= source.class.name %>)</p>
11
+ <% end %>
12
+
13
+ <%= will_paginate @sources %>