iqvoc_compound_forms 1.0.1

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.
Files changed (44) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +14 -0
  3. data/README.md +13 -0
  4. data/Rakefile +11 -0
  5. data/app/assets/javascripts/iqvoc_compound_forms/compound_forms.js +22 -0
  6. data/app/assets/javascripts/iqvoc_compound_forms/manifest.js +1 -0
  7. data/app/assets/javascripts/manifest.js +4 -0
  8. data/app/models/compound_form/base.rb +47 -0
  9. data/app/models/compound_form/content/base.rb +48 -0
  10. data/app/views/partials/compound_form/_base.html.erb +11 -0
  11. data/app/views/partials/compound_form/_compound_form.html.erb +17 -0
  12. data/app/views/partials/compound_form/_edit_base.html.erb +4 -0
  13. data/app/views/partials/compound_form/content/_base.html.erb +8 -0
  14. data/config.ru +4 -0
  15. data/config/application.rb +56 -0
  16. data/config/boot.rb +13 -0
  17. data/config/database.template.yml +30 -0
  18. data/config/engine.rb +13 -0
  19. data/config/environment.rb +5 -0
  20. data/config/environments/development.rb +55 -0
  21. data/config/environments/production.rb +64 -0
  22. data/config/environments/test.rb +46 -0
  23. data/config/initializers/engine_extensions.rb +7 -0
  24. data/config/initializers/iqvoc.rb +11 -0
  25. data/config/initializers/secret_token.rb.template +16 -0
  26. data/config/initializers/session_store.rb +11 -0
  27. data/config/locales/activerecord.de.yml +9 -0
  28. data/config/locales/activerecord.en.yml +9 -0
  29. data/config/locales/de.yml +12 -0
  30. data/config/locales/en.yml +12 -0
  31. data/config/routes.rb +2 -0
  32. data/db/migrate/20120112100000_create_compound_forms.rb +34 -0
  33. data/db/schema.rb +166 -0
  34. data/db/seeds.rb +0 -0
  35. data/iqvoc_compound_forms.gemspec +26 -0
  36. data/lib/engine_tasks/db.rake +19 -0
  37. data/lib/iqvoc/compound_forms/label_extensions.rb +72 -0
  38. data/lib/iqvoc/compound_forms/version.rb +5 -0
  39. data/lib/iqvoc_compound_forms.rb +15 -0
  40. data/public/.gitkeep +0 -0
  41. data/script/rails +6 -0
  42. data/test/test_helper.rb +10 -0
  43. data/test/unit/compound_form_test.rb +77 -0
  44. metadata +125 -0
@@ -0,0 +1,7 @@
1
+ /Gemfile.lock
2
+ /.bundle
3
+ /log
4
+ /tmp
5
+ /db/*.sqlite
6
+ /config/database.yml
7
+ /config/initializers/secret_token.rb
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'iqvoc', :path => '../iqvoc' # TODO: local path should be optional
4
+ gem 'iqvoc_skosxl', :path => '../iqvoc_skosxl' # TODO: local path should be optional
5
+
6
+ group :development, :test do
7
+ gem 'sqlite3'
8
+ end
9
+
10
+ group :test do
11
+ gem 'test-unit'
12
+ gem 'spork', '~> 0.9.0.rc' # v0.9 required for spork-testunit
13
+ gem 'spork-testunit'
14
+ end
@@ -0,0 +1,13 @@
1
+ Compound Forms for iQvoc
2
+
3
+
4
+ Getting Started
5
+ ===============
6
+
7
+ 1. Initialize database:
8
+
9
+ $ rake db:create iqvoc:db:migrate_all iqvoc:db:seed_all
10
+
11
+ 2. Generate secret token:
12
+
13
+ $ rake iqvoc:setup:generate_secret_token
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+ require 'rake'
7
+
8
+ Iqvoc::CompoundForms::Application.load_tasks
9
+
10
+ require 'bundler'
11
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,22 @@
1
+ /*jslint vars: true, unparam: true, browser: true */
2
+ /*global jQuery, IQVOC */
3
+
4
+ jQuery(document).ready(function($) {
5
+ "use strict";
6
+
7
+ $("input[type=button].add-compound-form").live("click", function(ev) {
8
+ var original = $(this).closest("li");
9
+ var clone = original.clone();
10
+ var container = $("div.entity_select", clone);
11
+ var el = $("input.entity_select", clone).
12
+ attr("data-entities", "").val("").insertBefore(container);
13
+ container.remove();
14
+ clone.insertAfter(original);
15
+ new IQVOC.EntitySelector(el[0]);
16
+ });
17
+
18
+ $("input[type=button].rm-compound-form").click(function(ev) {
19
+ // Remove the <li> that contains the widget
20
+ $(this).parent().remove();
21
+ });
22
+ });
@@ -0,0 +1 @@
1
+ //= require iqvoc_compound_forms/compound_forms
@@ -0,0 +1,4 @@
1
+ //= require framework
2
+ //= require iqvoc/manifest
3
+ //= require iqvoc_skosxl/manifest
4
+ //= require iqvoc_compound_forms/manifest
@@ -0,0 +1,47 @@
1
+ # encoding: UTF-8
2
+
3
+ class CompoundForm::Base < ActiveRecord::Base
4
+ class_attribute :rdf_namespace, :rdf_predicate
5
+ self.rdf_namespace = 'umt'
6
+ self.rdf_predicate = 'compoundForm'
7
+
8
+ set_table_name 'compound_forms'
9
+
10
+ belongs_to :domain, :class_name => 'Label::Base', :foreign_key => 'domain_id'
11
+
12
+ has_many :compound_form_contents,
13
+ :class_name => 'CompoundForm::Content::Base',
14
+ :foreign_key => 'compound_form_id',
15
+ :dependent => :destroy
16
+
17
+ scope :published, includes(:domain).merge(Label::Base.published)
18
+
19
+ def self.referenced_by(label_class)
20
+ # To something with the label class
21
+ end
22
+
23
+ def self.deep_cloning_relations
24
+ {self.name.to_relation_name => :compound_form_contents}
25
+ end
26
+
27
+ def self.view_section(obj)
28
+ "compound_forms"
29
+ end
30
+
31
+ def self.view_section_sort_key(obj)
32
+ 100
33
+ end
34
+
35
+ def self.partial_name(obj)
36
+ "partials/compound_form/base"
37
+ end
38
+
39
+ def self.edit_partial_name(obj)
40
+ "partials/compound_form/edit_base"
41
+ end
42
+
43
+ def build_rdf(document, subject)
44
+ subject.Umt.compoundForm(compound_form_contents.map {|cfc| IqRdf::build_uri(cfc.label.origin) })
45
+ end
46
+
47
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+
3
+ class CompoundForm::Content::Base < ActiveRecord::Base
4
+
5
+ set_table_name 'compound_form_contents'
6
+
7
+ belongs_to :compound_form, :class_name => 'CompoundForm::Base', :foreign_key => 'compound_form_id'
8
+ belongs_to :label, :class_name => 'Label::Base', :foreign_key => 'label_id'
9
+
10
+ scope :label_published, lambda {
11
+ includes(:label).merge(Label::Base.published)
12
+ }
13
+
14
+ scope :target_in_edit_mode, lambda { |domain_id| {
15
+ :joins => [:compound_form, :label],
16
+ :include => :label,
17
+ :conditions => "(compound_forms.domain_id = #{domain_id}) AND (labels.locked_by IS NOT NULL)" }
18
+ }
19
+
20
+ def self.referenced_by(label_class)
21
+ # To something with the label class
22
+ end
23
+
24
+ def self.deep_cloning_relations
25
+ self.name.to_relation_name
26
+ end
27
+
28
+ def self.view_section(obj)
29
+ "compound_forms"
30
+ end
31
+
32
+ def self.view_section_sort_key(obj)
33
+ 200
34
+ end
35
+
36
+ def self.partial_name(obj)
37
+ "partials/compound_form/content/base"
38
+ end
39
+
40
+ def self.edit_partial_name(obj)
41
+ "partials/compound_form/content/base" # Show data only
42
+ end
43
+
44
+ def build_rdf(document, subject)
45
+ #
46
+ end
47
+
48
+ end
@@ -0,0 +1,11 @@
1
+ <div class="relation">
2
+ <h4><%= t("txt.views.labels.compound_from") %></h4>
3
+ <div class="relation-body">
4
+ <%- label.send(klass.name.to_relation_name).each do |cf| -%>
5
+ <%= raw cf.compound_form_contents.label_published.map { |cfc|
6
+ link_to(cfc.label.value, label_path(:id => cfc.label))
7
+ }.join(', ') %>
8
+ <br />
9
+ <%- end -%>
10
+ </div>
11
+ </div>
@@ -0,0 +1,17 @@
1
+ <li class="compound-form">
2
+ <%= label_tag "inline_compound_form_origins",
3
+ CompoundForm::Base.model_name.human %>
4
+ <%- items = Iqvoc::XLLabel.base_class.editor_selectable.
5
+ by_origin(compound_form.compound_form_contents.
6
+ map { |cfc| cfc.label.origin }) -%>
7
+ <%= text_field_tag "label[inline_compound_form_origins][]",
8
+ items.join(Iqvoc::InlineDataHelper::Joiner),
9
+ :class => "entity_select",
10
+ :"data-query-url" => labels_path(:format => :json),
11
+ :"data-entity-uri" => label_path("{id}"),
12
+ :"data-entities" => (not compound_form) ? nil : items.
13
+ map { |l| label_widget_data(l) }.to_json %>
14
+
15
+ <input type="button" class="add-compound-form" value="<%= t("txt.common.add_note") %>">
16
+ <input type="button" class="rm-compound-form" value="<%= t("txt.common.delete") %>">
17
+ </li>
@@ -0,0 +1,4 @@
1
+ <%- label.compound_forms.build if label.compound_forms.empty? -%>
2
+ <% label.compound_forms.each do |compound_form| %>
3
+ <%= render 'partials/compound_form/compound_form', :label => label, :compound_form => compound_form, :klass => klass %>
4
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <div class="relation">
2
+ <h4><%= t("txt.views.labels.compound_in") %></h4>
3
+ <div class="relation-body">
4
+ <%= raw label.compound_in.map { |label|
5
+ link_to(label.value, label_path(:id => label))
6
+ }.join(', ') %>
7
+ </div>
8
+ </div>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Iqvoc::CompoundForms::Application
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ if defined?(Bundler)
6
+ # If you precompile assets before deploying to production, use this line
7
+ Bundler.require *Rails.groups(:assets => %w(development test))
8
+ # If you want your assets lazily compiled in production, use this line
9
+ # Bundler.require(:default, :assets, Rails.env)
10
+ end
11
+
12
+ module Iqvoc::CompoundForms
13
+ class Application < Rails::Application
14
+
15
+ # This has to be here because iqvoc_compound_forms.rb needs to know if it runs as app or as engine
16
+ require 'iqvoc_compound_forms'
17
+
18
+ # Settings in config/environments/* take precedence over those specified here.
19
+ # Application configuration should go into files in config/initializers
20
+ # -- all .rb files in that directory are automatically loaded.
21
+
22
+ # Custom directories with classes and modules you want to be autoloadable.
23
+ # config.autoload_paths += %W(#{config.root}/extras)
24
+
25
+ # Only load the plugins named here, in the order given (default is alphabetical).
26
+ # :all can be used as a placeholder for all plugins not explicitly named.
27
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
28
+
29
+ # Activate observers that should always be running.
30
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
31
+
32
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
33
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
34
+ # config.time_zone = 'Central Time (US & Canada)'
35
+
36
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
37
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
38
+ config.i18n.default_locale = :de
39
+ # config.i18n.available_locales = [:de, :en]
40
+
41
+ # JavaScript files you want as :defaults (application.js is always included).
42
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
43
+
44
+ # Configure the default encoding used in templates for Ruby 1.9.
45
+ config.encoding = "utf-8"
46
+
47
+ # Configure sensitive parameters which will be filtered from the log file.
48
+ config.filter_parameters += [:password, :password_confirmation]
49
+
50
+ # Enable the asset pipeline
51
+ config.assets.enabled = true
52
+
53
+ # Version of your assets, change this if you want to expire all your assets
54
+ config.assets.version = "1.0.1"
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ begin
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
7
+ require 'bundler'
8
+ Bundler.setup
9
+ rescue Bundler::GemNotFound => e
10
+ STDERR.puts e.message
11
+ STDERR.puts "Try running `bundle install`."
12
+ exit!
13
+ end if File.exist?(gemfile)
@@ -0,0 +1,30 @@
1
+ <% socket = [
2
+ "/tmp/mysql.sock",
3
+ "/opt/local/var/run/mysql5/mysqld.sock",
4
+ "/tmp/mysqld.sock",
5
+ "/var/run/mysqld.sock"
6
+ ].detect { |socket| File.exist?(socket) } %>
7
+
8
+ defaults: &defaults
9
+ encoding: utf8
10
+
11
+ development:
12
+ <<: *defaults
13
+ adapter: sqlite3
14
+ database: db/dev.sqlite
15
+
16
+ # Warning: The database defined as 'test' will be erased and
17
+ # re-generated from your development database when you run 'rake'.
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *defaults
21
+ adapter: sqlite3
22
+ database: db/test.sqlite
23
+
24
+ production:
25
+ <<: *defaults
26
+ adapter: mysql2
27
+ socket: <%= socket %>
28
+ username:
29
+ password:
30
+ database: iqvoc_compound_forms
@@ -0,0 +1,13 @@
1
+ require 'rails'
2
+
3
+ module Iqvoc
4
+ module CompoundForms
5
+
6
+ class Engine < Rails::Engine
7
+
8
+ paths["lib/tasks"] << "lib/engine_tasks"
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # Load the Rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application
5
+ Iqvoc::CompoundForms::Application.initialize!
@@ -0,0 +1,55 @@
1
+ if Iqvoc::CompoundForms.const_defined?(:Application)
2
+ Iqvoc::CompoundForms::Application.configure do
3
+ # Settings specified here will take precedence over those in config/environment.rb
4
+
5
+ # In the development environment your application's code is reloaded on
6
+ # every request. This slows down response time but is perfect for development
7
+ # since you don't have to restart the web server when you make code changes.
8
+ config.cache_classes = false
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+
26
+ # The default URI prefix for RDF data. This will be followed by a document-
27
+ # specific snippet like (specimenType) and the id.
28
+
29
+ # Do not compress assets
30
+ config.assets.compress = false
31
+
32
+ # Expands the lines which load the assets
33
+ config.assets.debug = false
34
+
35
+ # The JDBC driver URL for the connection to the virtuoso triple store.
36
+ # Login credentials have to be stored here too. See
37
+ # http://docs.openlinksw.com/virtuoso/VirtuosoDriverJDBC.html#jdbcurl4mat for
38
+ # more details.
39
+ # Example: "jdbc:virtuoso://localhost:1111/UID=dba/PWD=dba"
40
+ # Use nil to disable virtuoso triple synchronization
41
+ # Rails.application.config.virtuoso_jdbc_driver_url = "jdbc:virtuoso://virtuoso.dyndns.org:1111/UID=iqvoc/PWD=vocpass!/charset=UTF-8"
42
+ config.virtuoso_jdbc_driver_url = nil
43
+
44
+ # Set up the virtuoso synchronization (which is a triggered pull from the
45
+ # virtuoso server) to be run in a new thread.
46
+ # This is needed in environments where the web server only runs in a single
47
+ # process/thread (mostly in development environments).
48
+ # When a synchronization would be triggered e.g. from a running
49
+ # update action in the UPB, the update would trigger virtuoso to do a HTTP GET
50
+ # back to the UPB to fetch the RDF data. But the only process in the UPB would be
51
+ # blocked by the update... => Deadlock. You can avoid this by using the threaded
52
+ # mode.
53
+ config.virtuoso_sync_threaded = false
54
+ end
55
+ end
@@ -0,0 +1,64 @@
1
+ if Iqvoc::CompoundForms.const_defined?(:Application)
2
+ Iqvoc::CompoundForms::Application.configure do
3
+ # Settings specified here will take precedence over those in config/environment.rb
4
+
5
+ # The production environment is meant for finished, "live" apps.
6
+ # Code is not reloaded between requests
7
+ config.cache_classes = true
8
+
9
+ # Full error reports are disabled and caching is turned on
10
+ config.consider_all_requests_local = false
11
+ config.action_controller.perform_caching = true
12
+
13
+ # Specifies the header that your server uses for sending files
14
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
15
+
16
+ # For nginx:
17
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
18
+
19
+ # If you have no front-end server that supports something like X-Sendfile,
20
+ # just comment this out and Rails will serve the files
21
+
22
+ # See everything in the log (default is :info)
23
+ # config.log_level = :debug
24
+
25
+ # Use a different logger for distributed setups
26
+ # config.logger = SyslogLogger.new
27
+
28
+ # Use a different cache store in production
29
+ # config.cache_store = :mem_cache_store
30
+
31
+ # Disable Rails's static asset server
32
+ # In production, Apache or nginx will already do this
33
+ config.serve_static_assets = false
34
+
35
+ # Enable serving of images, stylesheets, and javascripts from an asset server
36
+ # config.action_controller.asset_host = "http://assets.example.com"
37
+
38
+ # Disable delivery errors, bad email addresses will be ignored
39
+ # config.action_mailer.raise_delivery_errors = false
40
+
41
+ # Enable threaded mode
42
+ # config.threadsafe!
43
+
44
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
45
+ # the I18n.default_locale when a translation can not be found)
46
+ config.i18n.fallbacks = true
47
+
48
+ # Send deprecation notices to registered listeners
49
+ config.active_support.deprecation = :notify
50
+
51
+ # Disable Rails's static asset server
52
+ # In production, Apache or nginx will already do this
53
+ config.serve_static_assets = false
54
+
55
+ # Compress JavaScripts and CSS
56
+ config.assets.compress = true
57
+
58
+ # Don't fallback to assets pipeline if a precompiled asset is missed
59
+ config.assets.compile = false
60
+
61
+ # Generate digests for assets URLs
62
+ config.assets.digest = true
63
+ end
64
+ end
@@ -0,0 +1,46 @@
1
+ if Iqvoc::CompoundForms.const_defined?(:Application)
2
+ Iqvoc::CompoundForms::Application.configure do
3
+ # Settings specified here will take precedence over those in config/environment.rb
4
+
5
+ config.autoload_paths += [Rails.root.join("test")]
6
+
7
+ # The test environment is used exclusively to run your application's
8
+ # test suite. You never need to work with it otherwise. Remember that
9
+ # your test database is "scratch space" for the test suite and is wiped
10
+ # and recreated between test runs. Don't rely on the data there!
11
+ config.cache_classes = true
12
+
13
+ # Log error messages when you accidentally call methods on nil.
14
+ config.whiny_nils = true
15
+
16
+ # Show full error reports and disable caching
17
+ config.consider_all_requests_local = true
18
+ config.action_controller.perform_caching = false
19
+
20
+ # Raise exceptions instead of rendering exception templates
21
+ config.action_dispatch.show_exceptions = false
22
+
23
+ # Disable request forgery protection in test environment
24
+ config.action_controller.allow_forgery_protection = false
25
+
26
+ # Tell Action Mailer not to deliver emails to the real world.
27
+ # The :test delivery method accumulates sent emails in the
28
+ # ActionMailer::Base.deliveries array.
29
+ config.action_mailer.delivery_method = :test
30
+
31
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
32
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
33
+ # like if you have constraints or database-specific column types
34
+ # config.active_record.schema_format = :sql
35
+
36
+ # Print deprecation notices to the stderr
37
+ config.active_support.deprecation = :stderr
38
+
39
+ # Configure static asset server for tests with Cache-Control for performance
40
+ config.serve_static_assets = true
41
+ config.static_cache_control = "public, max-age=3600"
42
+
43
+ # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
44
+ config.assets.allow_debugging = true
45
+ end
46
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: UTF-8
2
+
3
+ require "iqvoc/compound_forms/label_extensions"
4
+
5
+ Rails.application.config.to_prepare do
6
+ Label::SKOSXL::Base.send(:include, Iqvoc::CompoundForms::LabelExtensions)
7
+ end
@@ -0,0 +1,11 @@
1
+ # initializer for both iqvoc and iqvoc_skosxl
2
+
3
+ require 'iqvoc/xllabel' # XXX: this basically duplicates iqvoc_skosxl's initializer - but is required to ensure correct loading order!?
4
+
5
+ Iqvoc.title = "iQvoc Compound Forms"
6
+
7
+ Iqvoc::XLLabel.additional_association_class_names.
8
+ merge!("CompoundForm::Base" => "domain_id",
9
+ "CompoundForm::Content::Base" => "label_id") # used for the reverse direction ("compound_in")
10
+
11
+ Iqvoc::XLLabel.view_sections += ["compound_forms"]
@@ -0,0 +1,16 @@
1
+ # encoding: UTF-8
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ if Iqvoc::CompoundForms.const_defined?(:Application)
6
+
7
+ # Your secret key for verifying the integrity of signed cookies.
8
+ # If you change this key, all old signed cookies will become invalid!
9
+ # Make sure the secret is at least 30 characters and all random,
10
+ # no regular words or you'll be exposed to dictionary attacks.
11
+
12
+ # Run `rake secret` and uncomment the following line
13
+ # Replace the secret-placeholder with your generated token
14
+ Iqvoc::CompoundForms::Application.config.secret_token = "S-E-C-R-E-T"
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ if Iqvoc::CompoundForms.const_defined?(:Application)
4
+ Iqvoc::CompoundForms::Application.config.session_store :cookie_store,
5
+ :key => "_iqvoc_compound_forms_session"
6
+ end
7
+
8
+ # Use the database for sessions instead of the cookie-based default,
9
+ # which shouldn't be used to store highly confidential information
10
+ # (create the session table with "rake db:sessions:create")
11
+ # Iqvoc::Application.config.session_store :active_record_store
@@ -0,0 +1,9 @@
1
+ de:
2
+ activerecord:
3
+ models:
4
+ compound_form/base:
5
+ one: Zusammensetzung
6
+ other: Zusammensetzungen
7
+ compound_form/content/base:
8
+ one: Zusammengesetzt in
9
+ other: Zusammengesetzt in
@@ -0,0 +1,9 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ compound_form/base:
5
+ one: Compound Form
6
+ other: Compound Forms
7
+ compound_form/content/base:
8
+ one: Compound In
9
+ other: Compound In
@@ -0,0 +1,12 @@
1
+ de:
2
+ txt:
3
+ models:
4
+ label:
5
+ compound_form_contents_error: Eine Zusammensetzung muss aus min. 2 Labels bestehen.
6
+ views:
7
+ labels:
8
+ compound_from: Zusammengesetzt aus
9
+ compound_in: Zusammengesetzt in
10
+ widget:
11
+ delete_compound_form: Zusammensetzung löschen
12
+ create_compound_form: Neue Zusammensetzung
@@ -0,0 +1,12 @@
1
+ en:
2
+ txt:
3
+ models:
4
+ label:
5
+ compound_form_contents_error: Each composition must have at least two components.
6
+ views:
7
+ labels:
8
+ compound_from: Compound from
9
+ compound_in: Compound in
10
+ widget:
11
+ delete_compound_form: Delete Composition
12
+ create_compound_form: Add Composition
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,34 @@
1
+ class CreateCompoundForms < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ unless table_exists? "compound_form_contents"
5
+ create_table "compound_form_contents", :force => false do |t|
6
+ t.timestamps
7
+ t.integer "compound_form_id"
8
+ t.integer "label_id"
9
+ t.integer "order"
10
+ end
11
+ end
12
+ unless table_exists? "compound_forms"
13
+ create_table "compound_forms", :force => false do |t|
14
+ t.timestamps
15
+ t.integer "domain_id"
16
+ end
17
+ end
18
+
19
+ unless index_exists?("compound_forms", "domain_id", :name => "ix_cf_fk")
20
+ add_index "compound_forms", "domain_id", :name => "ix_cf_fk"
21
+ end
22
+ unless index_exists?("compound_form_contents", "compound_form_id", :name => "ix_cfc_compound_form_id")
23
+ add_index "compound_form_contents", "compound_form_id", :name => "ix_cfc_compound_form_id"
24
+ end
25
+ unless index_exists?("compound_form_contents", "label_id", :name => "ix_cfc_label_id")
26
+ add_index "compound_form_contents", "label_id", :name => "ix_cfc_label_id"
27
+ end
28
+ end
29
+
30
+ def self.down
31
+ # we don't want to delete existing data
32
+ end
33
+
34
+ end
@@ -0,0 +1,166 @@
1
+ # encoding: UTF-8
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
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # 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
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120112100000) do
15
+
16
+ create_table "collection_members", :force => true do |t|
17
+ t.integer "collection_id"
18
+ t.integer "target_id"
19
+ t.string "type"
20
+ end
21
+
22
+ add_index "collection_members", ["collection_id", "target_id", "type"], :name => "ix_collections_fk_type"
23
+
24
+ create_table "compound_form_contents", :force => true do |t|
25
+ t.datetime "created_at"
26
+ t.datetime "updated_at"
27
+ t.integer "compound_form_id"
28
+ t.integer "label_id"
29
+ t.integer "order"
30
+ end
31
+
32
+ add_index "compound_form_contents", ["compound_form_id"], :name => "ix_cfc_compound_form_id"
33
+ add_index "compound_form_contents", ["label_id"], :name => "ix_cfc_label_id"
34
+
35
+ create_table "compound_forms", :force => true do |t|
36
+ t.datetime "created_at"
37
+ t.datetime "updated_at"
38
+ t.integer "domain_id"
39
+ end
40
+
41
+ add_index "compound_forms", ["domain_id"], :name => "ix_cf_fk"
42
+
43
+ create_table "concept_relations", :force => true do |t|
44
+ t.string "type"
45
+ t.integer "owner_id"
46
+ t.integer "target_id"
47
+ t.datetime "created_at"
48
+ t.datetime "updated_at"
49
+ end
50
+
51
+ add_index "concept_relations", ["owner_id", "target_id"], :name => "ix_concept_relations_fk"
52
+
53
+ create_table "concepts", :force => true do |t|
54
+ t.string "type"
55
+ t.string "origin", :limit => 4000
56
+ t.integer "rev", :default => 1
57
+ t.date "published_at"
58
+ t.integer "published_version_id"
59
+ t.integer "locked_by"
60
+ t.date "expired_at"
61
+ t.date "follow_up"
62
+ t.boolean "to_review"
63
+ t.date "rdf_updated_at"
64
+ t.datetime "created_at"
65
+ t.datetime "updated_at"
66
+ end
67
+
68
+ add_index "concepts", ["origin"], :name => "ix_concepts_on_origin"
69
+ add_index "concepts", ["published_version_id"], :name => "ix_concepts_publ_version_id"
70
+
71
+ create_table "label_relations", :force => true do |t|
72
+ t.string "type"
73
+ t.integer "domain_id"
74
+ t.integer "range_id"
75
+ t.datetime "created_at"
76
+ t.datetime "updated_at"
77
+ end
78
+
79
+ add_index "label_relations", ["domain_id", "range_id", "type"], :name => "ix_label_rel_dom_rng_type"
80
+ add_index "label_relations", ["type"], :name => "ix_label_relations_on_type"
81
+
82
+ create_table "labelings", :force => true do |t|
83
+ t.string "type"
84
+ t.integer "owner_id"
85
+ t.integer "target_id"
86
+ t.datetime "created_at"
87
+ t.datetime "updated_at"
88
+ end
89
+
90
+ add_index "labelings", ["owner_id", "target_id", "type"], :name => "ix_labelings_fk_type"
91
+ add_index "labelings", ["type"], :name => "ix_labelings_on_type"
92
+
93
+ create_table "labels", :force => true do |t|
94
+ t.string "type"
95
+ t.string "origin", :limit => 4000
96
+ t.string "language"
97
+ t.string "value", :limit => 1024
98
+ t.datetime "created_at"
99
+ t.datetime "updated_at"
100
+ t.integer "rev", :default => 1
101
+ t.integer "published_version_id"
102
+ t.date "published_at"
103
+ t.integer "locked_by"
104
+ t.date "expired_at"
105
+ t.date "follow_up"
106
+ t.boolean "to_review"
107
+ t.date "rdf_updated_at"
108
+ end
109
+
110
+ add_index "labels", ["language"], :name => "ix_labels_on_language"
111
+ add_index "labels", ["origin"], :name => "ix_labels_on_origin"
112
+ add_index "labels", ["published_version_id"], :name => "ix_labels_on_published_v"
113
+ add_index "labels", ["value"], :name => "ix_labels_on_value"
114
+
115
+ create_table "matches", :force => true do |t|
116
+ t.integer "concept_id"
117
+ t.string "type"
118
+ t.string "value"
119
+ t.datetime "created_at"
120
+ t.datetime "updated_at"
121
+ end
122
+
123
+ add_index "matches", ["concept_id", "type"], :name => "ix_matches_fk_type"
124
+ add_index "matches", ["type"], :name => "ix_matches_on_type"
125
+
126
+ create_table "note_annotations", :force => true do |t|
127
+ t.integer "note_id"
128
+ t.string "predicate", :limit => 50
129
+ t.string "value", :limit => 1024
130
+ t.datetime "created_at"
131
+ t.datetime "updated_at"
132
+ t.string "namespace", :limit => 50
133
+ end
134
+
135
+ add_index "note_annotations", ["note_id"], :name => "ix_note_annotations_fk"
136
+
137
+ create_table "notes", :force => true do |t|
138
+ t.string "language", :limit => 2
139
+ t.string "value", :limit => 4000
140
+ t.string "type", :limit => 50
141
+ t.datetime "created_at"
142
+ t.datetime "updated_at"
143
+ t.integer "owner_id"
144
+ t.string "owner_type", :null => false
145
+ end
146
+
147
+ add_index "notes", ["language"], :name => "ix_notes_on_language"
148
+ add_index "notes", ["owner_id", "owner_type", "type"], :name => "ix_notes_fk_type"
149
+ add_index "notes", ["type"], :name => "ix_notes_on_type"
150
+
151
+ create_table "users", :force => true do |t|
152
+ t.string "forename"
153
+ t.string "surname"
154
+ t.string "email"
155
+ t.string "crypted_password"
156
+ t.boolean "active"
157
+ t.datetime "created_at"
158
+ t.datetime "updated_at"
159
+ t.string "password_salt"
160
+ t.string "persistence_token"
161
+ t.string "perishable_token"
162
+ t.string "role"
163
+ t.string "telephone_number"
164
+ end
165
+
166
+ end
File without changes
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "iqvoc/compound_forms/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "iqvoc_compound_forms"
8
+ s.version = Iqvoc::CompoundForms::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Robert Glaser", "Till Schulte-Coerne", "Frederik Dohr"]
11
+ s.email = ["robert.glaser@innoq.com"]
12
+ s.homepage = "" # TODO
13
+ s.summary = "" # TODO
14
+ s.description = "" # TODO
15
+
16
+ s.rubyforge_project = "iqvoc_compound_forms"
17
+
18
+ s.add_dependency "rails", "~> 3.1.3"
19
+ s.add_dependency "iqvoc"
20
+ s.add_dependency "iqvoc_skosxl"
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ namespace :iqvoc_compound_forms do
4
+ namespace :db do
5
+
6
+ desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking db:schema:dump. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
7
+ task :migrate => :environment do
8
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
9
+ ActiveRecord::Migrator.migrate(Iqvoc::CompoundForms::Engine.find_root_with_flag("db").join('db/migrate'), ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
10
+ Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
11
+ end
12
+
13
+ desc "Load seeds (task is idempotent)"
14
+ task :seed => :environment do
15
+ Iqvoc::CompoundForms::Engine.load_seed
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: UTF-8
2
+
3
+ require "active_support/concern"
4
+
5
+ module Iqvoc::CompoundForms::LabelExtensions
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ after_save do |label|
10
+ # Compound forms
11
+ # Only handle compound form creation if there are submitted widget values
12
+ # Otherwise compound_forms would be destroyed on every save (e.g. in the branching process)!
13
+ if inline_compound_form_origins.present?
14
+ compound_forms.destroy_all
15
+ inline_compound_form_origins.each do |origin_collection|
16
+ compound_form_contents = []
17
+ origin_collection.each_with_index do |origin, index|
18
+ if label = Iqvoc::XLLabel.base_class.editor_selectable.by_origin(origin).last
19
+ compound_form_contents << CompoundForm::Content::Base.new(:label => label, :order => index)
20
+ end
21
+ end
22
+ compound_forms.create!(:compound_form_contents => compound_form_contents)
23
+ end
24
+ end
25
+ end
26
+
27
+ has_many :compound_forms,
28
+ :class_name => "CompoundForm::Base",
29
+ :foreign_key => "domain_id",
30
+ :dependent => :destroy
31
+
32
+ has_many :compound_form_contents,
33
+ :through => :compound_forms,
34
+ :class_name => "CompoundForm::Content::Base",
35
+ :dependent => :destroy
36
+
37
+ validate :compound_form_contents_size
38
+ end
39
+
40
+ module InstanceMethods
41
+ def compound_in
42
+ CompoundForm::Base.joins(:compound_form_contents).
43
+ where(:compound_form_contents => { :label_id => id }).
44
+ includes(:domain).map(&:domain)
45
+ end
46
+
47
+ # Serialized setters and getters (\r\n or , separated)
48
+ def inline_compound_form_origins
49
+ @inline_compound_form_origins || []
50
+ end
51
+
52
+ def inline_compound_form_origins=(value_collection)
53
+ # write to instance variable and write it on after_safe
54
+ @inline_compound_form_origins = []
55
+
56
+ value_collection.reject(&:blank?).each do |value|
57
+ @inline_compound_form_origins << value.split(/\r\n|, */).map(&:strip). # XXX: use Iqvoc::InlineDataHelper?
58
+ reject(&:blank?).uniq
59
+ end
60
+ end
61
+
62
+ def compound_form_contents_size
63
+ if @full_validation
64
+ compound_forms.each do |cf|
65
+ if cf.compound_form_contents.count < 2
66
+ errors.add :base, I18n.t("txt.models.label.compound_form_contents_error")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Iqvoc
2
+ module CompoundForms
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'iqvoc/compound_forms/version'
4
+
5
+ module IqvocCompoundForms
6
+
7
+ unless Iqvoc.const_defined?(:CompoundForms) && Iqvoc::CompoundForms.const_defined?(:Application)
8
+ require File.join(File.dirname(__FILE__), '../config/engine')
9
+ end
10
+
11
+ ActiveSupport.on_load(:after_iqvoc_config) do
12
+ require 'iqvoc'
13
+ end
14
+
15
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,10 @@
1
+ require 'spork'
2
+
3
+ Spork.prefork do
4
+ ENV["RAILS_ENV"] = "test"
5
+ require File.expand_path('../../config/environment', __FILE__)
6
+ require 'rails/test_help'
7
+ end
8
+
9
+ Spork.each_run do
10
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../test_helper')
4
+
5
+ class CompoundFormTest < ActiveSupport::TestCase
6
+
7
+ setup do
8
+ @compounds = {
9
+ "Weltraumkampfpilot" => %w(Weltraum Kampf Pilot)
10
+ }
11
+ end
12
+
13
+ test "instance creation" do
14
+ @compounds.each do |term, components|
15
+ label = Iqvoc::XLLabel.base_class.create!(:value => term,
16
+ "origin" => OriginMapping.merge(term),
17
+ "language" => Iqvoc::Concept.pref_labeling_languages.first,
18
+ "published_at" => 2.days.ago)
19
+ label.compound_forms.create!(:compound_form_contents => components.
20
+ each_with_index.map { |cterm, i|
21
+ clabel = Iqvoc::XLLabel.base_class.create!(:value => cterm,
22
+ "origin" => OriginMapping.merge(cterm),
23
+ "language" => Iqvoc::Concept.pref_labeling_languages.first,
24
+ "published_at" => 2.days.ago)
25
+ CompoundForm::Content::Base.new(:label => clabel, :order => i)
26
+ })
27
+ end
28
+
29
+ assert_equal 4, Label::Base.count
30
+ assert_equal 1, CompoundForm::Base.count
31
+ assert_equal 3, CompoundForm::Content::Base.count
32
+
33
+ label = Label::Base.find_by_value("Weltraumkampfpilot")
34
+ assert_equal 1, label.compound_forms.count
35
+ assert_equal %w(Weltraum Kampf Pilot), label.compound_forms.first.
36
+ compound_form_contents.map { |cfc| cfc.label.value }
37
+
38
+ %w(Weltraum Kampf Pilot).each { |term|
39
+ sublabel = Label::Base.find_by_value(term)
40
+ assert_equal 1, sublabel.compound_in.count
41
+ assert_equal label, sublabel.compound_in.first
42
+ }
43
+ end
44
+
45
+ test "inline assignment" do
46
+ terms = @compounds.map { |term, components|
47
+ [term] + components
48
+ }.flatten
49
+ labels = terms.map { |term|
50
+ Iqvoc::XLLabel.base_class.create!(:value => term,
51
+ "origin" => OriginMapping.merge(term),
52
+ "language" => Iqvoc::Concept.pref_labeling_languages.first,
53
+ "published_at" => 2.days.ago)
54
+ }
55
+
56
+ label = labels.first
57
+ inline_values = labels[1...labels.length].map(&:origin).join(",")
58
+ label.inline_compound_form_origins = [inline_values]
59
+ label.save
60
+
61
+ assert_equal 4, Label::Base.count
62
+ assert_equal 1, CompoundForm::Base.count
63
+ assert_equal 3, CompoundForm::Content::Base.count
64
+
65
+ label = Label::Base.find_by_value("Weltraumkampfpilot")
66
+ assert_equal 1, label.compound_forms.count
67
+ assert_equal %w(Weltraum Kampf Pilot), label.compound_forms.first.
68
+ compound_form_contents.map { |cfc| cfc.label.value }
69
+
70
+ %w(Weltraum Kampf Pilot).each { |term|
71
+ sublabel = Label::Base.find_by_value(term)
72
+ assert_equal 1, sublabel.compound_in.count
73
+ assert_equal label, sublabel.compound_in.first
74
+ }
75
+ end
76
+
77
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iqvoc_compound_forms
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Glaser
9
+ - Till Schulte-Coerne
10
+ - Frederik Dohr
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-01-16 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rails
18
+ requirement: &70212432428360 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 3.1.3
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70212432428360
27
+ - !ruby/object:Gem::Dependency
28
+ name: iqvoc
29
+ requirement: &70212432426900 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70212432426900
38
+ - !ruby/object:Gem::Dependency
39
+ name: iqvoc_skosxl
40
+ requirement: &70212432424500 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *70212432424500
49
+ description: ''
50
+ email:
51
+ - robert.glaser@innoq.com
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - Gemfile
58
+ - README.md
59
+ - Rakefile
60
+ - app/assets/javascripts/iqvoc_compound_forms/compound_forms.js
61
+ - app/assets/javascripts/iqvoc_compound_forms/manifest.js
62
+ - app/assets/javascripts/manifest.js
63
+ - app/models/compound_form/base.rb
64
+ - app/models/compound_form/content/base.rb
65
+ - app/views/partials/compound_form/_base.html.erb
66
+ - app/views/partials/compound_form/_compound_form.html.erb
67
+ - app/views/partials/compound_form/_edit_base.html.erb
68
+ - app/views/partials/compound_form/content/_base.html.erb
69
+ - config.ru
70
+ - config/application.rb
71
+ - config/boot.rb
72
+ - config/database.template.yml
73
+ - config/engine.rb
74
+ - config/environment.rb
75
+ - config/environments/development.rb
76
+ - config/environments/production.rb
77
+ - config/environments/test.rb
78
+ - config/initializers/engine_extensions.rb
79
+ - config/initializers/iqvoc.rb
80
+ - config/initializers/secret_token.rb.template
81
+ - config/initializers/session_store.rb
82
+ - config/locales/activerecord.de.yml
83
+ - config/locales/activerecord.en.yml
84
+ - config/locales/de.yml
85
+ - config/locales/en.yml
86
+ - config/routes.rb
87
+ - db/migrate/20120112100000_create_compound_forms.rb
88
+ - db/schema.rb
89
+ - db/seeds.rb
90
+ - iqvoc_compound_forms.gemspec
91
+ - lib/engine_tasks/db.rake
92
+ - lib/iqvoc/compound_forms/label_extensions.rb
93
+ - lib/iqvoc/compound_forms/version.rb
94
+ - lib/iqvoc_compound_forms.rb
95
+ - public/.gitkeep
96
+ - script/rails
97
+ - test/test_helper.rb
98
+ - test/unit/compound_form_test.rb
99
+ homepage: ''
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project: iqvoc_compound_forms
119
+ rubygems_version: 1.8.10
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: ''
123
+ test_files:
124
+ - test/test_helper.rb
125
+ - test/unit/compound_form_test.rb