hydramata-works 0.0.1.prerelease
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.hound.yml +818 -0
- data/.rspec +2 -0
- data/.travis.yml +20 -0
- data/CONTRIBUTING.md +220 -0
- data/Gemfile +36 -0
- data/Guardfile +36 -0
- data/LICENSE +15 -0
- data/README.md +36 -0
- data/Rakefile +47 -0
- data/TODO.md +74 -0
- data/VISION.md +19 -0
- data/app/forms/hydramata/works/entity_form.rb +92 -0
- data/app/forms/hydramata/works/validation_service.rb +78 -0
- data/app/models/hydramata/works/data_definition.rb +57 -0
- data/app/models/hydramata/works/entities.rb +11 -0
- data/app/models/hydramata/works/entity.rb +75 -0
- data/app/models/hydramata/works/predicate.rb +35 -0
- data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
- data/app/models/hydramata/works/predicate_set.rb +44 -0
- data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
- data/app/models/hydramata/works/predicates.rb +14 -0
- data/app/models/hydramata/works/predicates/storage.rb +33 -0
- data/app/models/hydramata/works/presentation_structure.rb +29 -0
- data/app/models/hydramata/works/property.rb +72 -0
- data/app/models/hydramata/works/property_set.rb +89 -0
- data/app/models/hydramata/works/validations.rb +6 -0
- data/app/models/hydramata/works/value.rb +34 -0
- data/app/models/hydramata/works/work_type.rb +49 -0
- data/app/models/hydramata/works/work_types.rb +14 -0
- data/app/models/hydramata/works/work_types/storage.rb +42 -0
- data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
- data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
- data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
- data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
- data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
- data/app/parsers/hydramata/works/validations_parser.rb +22 -0
- data/app/parsers/hydramata/works/value_parser.rb +26 -0
- data/app/parsers/hydramata/works/value_parsers.rb +27 -0
- data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
- data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
- data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
- data/app/presenters/hydramata/works/base_presenter.rb +146 -0
- data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
- data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
- data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
- data/app/presenters/hydramata/works/property_presenter.rb +51 -0
- data/app/presenters/hydramata/works/value_presenter.rb +60 -0
- data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
- data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
- data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
- data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
- data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
- data/app/views/hydramata/works/properties/_show.html.erb +3 -0
- data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
- data/app/views/hydramata/works/works/_edit.html.erb +8 -0
- data/app/views/hydramata/works/works/_new.html.erb +8 -0
- data/app/views/hydramata/works/works/_show.html.erb +3 -0
- data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
- data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
- data/bin/rails +12 -0
- data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
- data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
- data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
- data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
- data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
- data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
- data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
- data/db/seeds.rb +36 -0
- data/documents/administrative-set-strawperson.md +45 -0
- data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
- data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
- data/documents/diagrams/hydramata-work-architecture.dot +129 -0
- data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
- data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
- data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
- data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
- data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
- data/documents/diagrams/work-rendering.dot +53 -0
- data/documents/diagrams/work-structure.dot +32 -0
- data/documents/handling-work.md +224 -0
- data/documents/high-level-stories.md +105 -0
- data/documents/hydramata-components.md +82 -0
- data/documents/interface-between-work-and-permissions.md +131 -0
- data/documents/interface-between-work-and-workflow.md +6 -0
- data/documents/timeline.md +75 -0
- data/fs +3 -0
- data/gemfiles/rails4.1.gemfile +12 -0
- data/gemfiles/rails4.gemfile +13 -0
- data/hydramata-works.gemspec +43 -0
- data/lib/hydramata-works.rb +23 -0
- data/lib/hydramata/works/conversions.rb +21 -0
- data/lib/hydramata/works/conversions/exceptions.rb +18 -0
- data/lib/hydramata/works/conversions/predicate.rb +22 -0
- data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
- data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
- data/lib/hydramata/works/conversions/presenter.rb +13 -0
- data/lib/hydramata/works/conversions/property.rb +31 -0
- data/lib/hydramata/works/conversions/property_set.rb +23 -0
- data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
- data/lib/hydramata/works/conversions/value.rb +20 -0
- data/lib/hydramata/works/conversions/work_type.rb +26 -0
- data/lib/hydramata/works/engine.rb +31 -0
- data/lib/hydramata/works/linters.rb +99 -0
- data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
- data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
- data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
- data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
- data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
- data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
- data/lib/hydramata/works/translator.rb +67 -0
- data/lib/hydramata/works/version.rb +5 -0
- data/lib/hydramata_works.rb +2 -0
- data/lib/tasks/hydramata_work_tasks.rake +4 -0
- data/run_each_spec_in_isolation +16 -0
- data/run_each_spec_in_isolation.txt +110 -0
- data/script/analyzer.rb +124 -0
- data/script/fast_specs +22 -0
- data/spec/features/fedora_to_in_memory_spec.rb +60 -0
- data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
- data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
- data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
- data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
- data/spec/features/translation_services_spec.rb +107 -0
- data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
- data/spec/fixtures/cassettes/fedora-object.yml +299 -0
- data/spec/fixtures/translations.yml +20 -0
- data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
- data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
- data/spec/lib/hydramata-work_spec.rb +14 -0
- data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
- data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
- data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
- data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
- data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
- data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
- data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
- data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
- data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
- data/spec/lib/hydramata/works/translator_spec.rb +81 -0
- data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
- data/spec/models/hydramata/works/entity_spec.rb +50 -0
- data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
- data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
- data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
- data/spec/models/hydramata/works/predicate_spec.rb +16 -0
- data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
- data/spec/models/hydramata/works/predicates_spec.rb +18 -0
- data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
- data/spec/models/hydramata/works/property_set_spec.rb +135 -0
- data/spec/models/hydramata/works/property_spec.rb +74 -0
- data/spec/models/hydramata/works/value_spec.rb +61 -0
- data/spec/models/hydramata/works/work_type_spec.rb +45 -0
- data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
- data/spec/models/hydramata/works/work_types_spec.rb +16 -0
- data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
- data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
- data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
- data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
- data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
- data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
- data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
- data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
- data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
- data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
- data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
- data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
- data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
- data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
- data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
- data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
- data/spec/spec_active_record_helper.rb +30 -0
- data/spec/spec_fast_helper.rb +12 -0
- data/spec/spec_slow_helper.rb +56 -0
- data/spec/spec_view_helper.rb +14 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
- data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
- data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
- data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
- data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
- data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
- data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
- data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
- data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
- metadata +466 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
module DatastreamParsers
|
4
|
+
# Responsible for parsing an ntriples encoded datastructure.
|
5
|
+
class RdfNtriplesParser
|
6
|
+
def self.match?(options = {})
|
7
|
+
datastream = options[:datastream]
|
8
|
+
return false unless datastream
|
9
|
+
if datastream.mimeType == 'text/plain' &&
|
10
|
+
datastream.content =~ /\A\<info:fedora/
|
11
|
+
self
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.call(data, collaborators = {}, &block)
|
18
|
+
new(collaborators).call(data, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(collaborators = {})
|
22
|
+
@graph = collaborators.fetch(:graph) { default_graph }
|
23
|
+
@reader = collaborators.fetch(:reader) { default_reader }
|
24
|
+
@pattern = collaborators.fetch(:pattern) { default_pattern }
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(data, &block)
|
28
|
+
query_graph_with(data, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def query_graph_with(data)
|
34
|
+
graph << reader.new(data)
|
35
|
+
graph.query(pattern).each_statement do |statement|
|
36
|
+
yield(predicate: statement.predicate.to_s, value: statement.object)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :graph, :reader, :pattern
|
41
|
+
private :graph, :reader, :pattern
|
42
|
+
|
43
|
+
def default_graph
|
44
|
+
require 'rdf'
|
45
|
+
RDF::Graph.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_reader
|
49
|
+
require 'rdf'
|
50
|
+
RDF::Reader.for(:ntriples)
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_pattern
|
54
|
+
require 'rdf'
|
55
|
+
RDF::Query::Pattern.from([:s, :p, :o])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
module DatastreamParsers
|
4
|
+
# Responsible for parsing a very simplistic XML document.
|
5
|
+
module SimpleXmlParser
|
6
|
+
module_function
|
7
|
+
def match?(options = {})
|
8
|
+
datastream = options[:datastream]
|
9
|
+
return false unless datastream
|
10
|
+
if datastream.mimeType =~ /\A(application|text)\/xml/
|
11
|
+
self
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(content, &block)
|
18
|
+
require 'nokogiri'
|
19
|
+
doc = Nokogiri::XML.parse(content)
|
20
|
+
doc.xpath('/fields/*').each do |node|
|
21
|
+
block.call(predicate: node.name, value: node.text)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
# Responsible for finding the appropriate predicate parser based on the
|
4
|
+
# input context, then calling the found parser.
|
5
|
+
#
|
6
|
+
# See lib/hydramata/works/linters.rb for the interface definition of a
|
7
|
+
# datastream parser.
|
8
|
+
module PredicateParser
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def call(options = {}, &block)
|
12
|
+
parser = parser_for(options)
|
13
|
+
value = options.fetch(:value)
|
14
|
+
parser.call(value, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def parser_for(options = {})
|
18
|
+
parser_finder = options.fetch(:parser_finder) { default_parser_finder }
|
19
|
+
parser_finder.call(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_parser_finder
|
23
|
+
proc do
|
24
|
+
require 'hydramata/works/predicate_parsers/simple_parser'
|
25
|
+
PredicateParsers::SimpleParser
|
26
|
+
end
|
27
|
+
end
|
28
|
+
private_class_method :default_parser_finder
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Hydramata
|
3
|
+
module Works
|
4
|
+
module ValidationsParser
|
5
|
+
module_function
|
6
|
+
def call(input)
|
7
|
+
case input
|
8
|
+
when NilClass then {}
|
9
|
+
when String then
|
10
|
+
if input.empty?
|
11
|
+
{}
|
12
|
+
else
|
13
|
+
JSON.parse(input)
|
14
|
+
end
|
15
|
+
when Hash then input
|
16
|
+
else
|
17
|
+
raise RuntimeError, "Unable to parse #{input.inspect} for Validations"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
module ValueParser
|
4
|
+
module_function
|
5
|
+
def call(options = {}, &block)
|
6
|
+
parser = parser_for(options)
|
7
|
+
value = options.fetch(:value)
|
8
|
+
parser.call(value, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def parser_for(options = {})
|
12
|
+
parser_finder = options.fetch(:parser_finder) { default_parser_finder }
|
13
|
+
parser_finder.call(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_parser_finder
|
17
|
+
->(options) do
|
18
|
+
require 'hydramata/works/value_parsers'
|
19
|
+
ValueParsers.find(options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
private_class_method :default_parser_finder
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'hydramata/works/value_parsers/simple_parser'
|
2
|
+
require 'hydramata/works/value_parsers/date_parser'
|
3
|
+
require 'hydramata/works/value_parsers/interrogation_parser'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
module ValueParsers
|
8
|
+
module_function
|
9
|
+
def find(options = {})
|
10
|
+
predicate = options.fetch(:predicate)
|
11
|
+
parser_class_name = predicate.value_parser_name
|
12
|
+
|
13
|
+
# Catching behavioral difference between const_defined? in Ruby 2.0 and
|
14
|
+
# Ruby 2.1
|
15
|
+
if parser_class_name =~ /\A::/
|
16
|
+
SimpleParser
|
17
|
+
elsif const_defined?(parser_class_name)
|
18
|
+
const_get(parser_class_name)
|
19
|
+
else
|
20
|
+
SimpleParser
|
21
|
+
end
|
22
|
+
rescue NameError, TypeError
|
23
|
+
SimpleParser
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
module ValueParsers
|
4
|
+
module InterrogationParser
|
5
|
+
module_function
|
6
|
+
def call(object, &block)
|
7
|
+
value =
|
8
|
+
case object
|
9
|
+
when RDF::Literal then object.to_s
|
10
|
+
else
|
11
|
+
object
|
12
|
+
end
|
13
|
+
block.call(value: value, raw_object: object)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Hydramata
|
2
|
+
module Works
|
3
|
+
module ValueParsers
|
4
|
+
# A comically simple parser.
|
5
|
+
# You get what you give.
|
6
|
+
module SimpleParser
|
7
|
+
module_function
|
8
|
+
def call(object, &block)
|
9
|
+
block.call(value: object, raw_object: object)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'active_support/core_ext/array/wrap'
|
3
|
+
require 'hydramata/works/conversions/translation_key_fragment'
|
4
|
+
|
5
|
+
module Hydramata
|
6
|
+
module Works
|
7
|
+
# Responsible for coordinating the rendering of an in-memory data structure
|
8
|
+
# object to an output buffer.
|
9
|
+
class BasePresenter < SimpleDelegator
|
10
|
+
include Conversions
|
11
|
+
attr_reader :presentation_context, :translator, :partial_prefixes, :template_missing_error, :translation_scopes
|
12
|
+
def initialize(object, collaborators = {})
|
13
|
+
__setobj__(object)
|
14
|
+
@presentation_context = collaborators.fetch(:presentation_context) { default_presentation_context }
|
15
|
+
@translator = collaborators.fetch(:translator) { default_translator }
|
16
|
+
@partial_prefixes = collaborators.fetch(:partial_prefixes) { default_partial_prefixes }
|
17
|
+
@translation_scopes = collaborators.fetch(:translation_scopes) { default_translation_scopes }
|
18
|
+
@template_missing_error = collaborators.fetch(:template_missing_exception) { default_template_missing_exception }
|
19
|
+
@dom_attributes_builder = collaborators.fetch(:dom_attributes_builder) { default_dom_attributes_builder }
|
20
|
+
end
|
21
|
+
|
22
|
+
def render(options = {})
|
23
|
+
template = options.fetch(:template)
|
24
|
+
rendering_options = rendering_options_for(options)
|
25
|
+
render_with_diminishing_specificity(template, rendering_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
format('#<%s:%#0x presenting=%s>', self.class, __id__, __getobj__.inspect)
|
30
|
+
end
|
31
|
+
|
32
|
+
def instance_of?(klass)
|
33
|
+
super || __getobj__.instance_of?(klass)
|
34
|
+
end
|
35
|
+
|
36
|
+
def dom_class(options = {})
|
37
|
+
prefix = options.fetch(:prefix, nil)
|
38
|
+
suffix = options.fetch(:suffix, nil)
|
39
|
+
[prefix, base_dom_class, suffix].compact.join('-')
|
40
|
+
end
|
41
|
+
|
42
|
+
def translate(key)
|
43
|
+
translator.t(key, scopes: translation_scopes, default: default_translation_for(key))
|
44
|
+
end
|
45
|
+
alias_method :t, :translate
|
46
|
+
|
47
|
+
def name
|
48
|
+
__getobj__.respond_to?(:name) ? __getobj__.name : __getobj__.name_for_application_usage
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_presenter
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def container_content_tag_attributes(options = {})
|
56
|
+
dom_attributes_builder.call(self, options, default_dom_attributes)
|
57
|
+
end
|
58
|
+
|
59
|
+
def presenter_dom_class
|
60
|
+
self.class.to_s.split('::').last.sub(/presenter\Z/i,'').downcase
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
attr_reader :dom_attributes_builder
|
66
|
+
def default_dom_attributes_builder
|
67
|
+
require 'hydramata/works/dom_attributes_builder'
|
68
|
+
DomAttributesBuilder
|
69
|
+
end
|
70
|
+
|
71
|
+
def default_dom_attributes
|
72
|
+
{}
|
73
|
+
end
|
74
|
+
|
75
|
+
def base_dom_class
|
76
|
+
name.to_s.downcase.gsub(/[\W_]+/, '-')
|
77
|
+
end
|
78
|
+
|
79
|
+
def render_with_diminishing_specificity(template, rendering_options)
|
80
|
+
render_with_prefixes(template, rendering_options) || render_without_prefixes(template, rendering_options)
|
81
|
+
end
|
82
|
+
|
83
|
+
def render_with_prefixes(template, rendering_options)
|
84
|
+
rendered = nil
|
85
|
+
partial_prefixes.each do |partial_prefix|
|
86
|
+
begin
|
87
|
+
rendered = template.render(rendering_options.merge(partial: partial_name(partial_prefix)))
|
88
|
+
break
|
89
|
+
# By using the splat operator I am allowing multiple exceptions to
|
90
|
+
# be caught and pass to the next rendering context.
|
91
|
+
rescue *template_missing_error
|
92
|
+
next
|
93
|
+
end
|
94
|
+
end
|
95
|
+
rendered
|
96
|
+
end
|
97
|
+
|
98
|
+
def render_without_prefixes(template, rendering_options)
|
99
|
+
template.render(rendering_options.merge(partial: partial_name))
|
100
|
+
end
|
101
|
+
|
102
|
+
def default_partial_prefixes
|
103
|
+
[]
|
104
|
+
end
|
105
|
+
|
106
|
+
def default_translation_scopes
|
107
|
+
[]
|
108
|
+
end
|
109
|
+
|
110
|
+
def rendering_options_for(options = {})
|
111
|
+
returning_options = { object: self }
|
112
|
+
returning_options[:locals] = options[:locals] if options.key?(:locals)
|
113
|
+
returning_options
|
114
|
+
end
|
115
|
+
|
116
|
+
def partial_name(*current_partial_prefixes)
|
117
|
+
partial_prefix = Array.wrap(current_partial_prefixes).join("/")
|
118
|
+
File.join('hydramata/works', view_path_slug_for_object, partial_prefix , presentation_context.to_s)
|
119
|
+
end
|
120
|
+
|
121
|
+
def default_presentation_context
|
122
|
+
'show'
|
123
|
+
end
|
124
|
+
|
125
|
+
def view_path_slug_for_object
|
126
|
+
'base'
|
127
|
+
end
|
128
|
+
|
129
|
+
def default_translation_for(key)
|
130
|
+
proc { send(key).to_s }
|
131
|
+
end
|
132
|
+
|
133
|
+
def default_translator
|
134
|
+
require 'hydramata/works/translator'
|
135
|
+
Translator
|
136
|
+
end
|
137
|
+
|
138
|
+
# Because actually testing this is somewhat of a nightmare given the
|
139
|
+
# 5+ parameters that are required when instantiating this exception.
|
140
|
+
def default_template_missing_exception
|
141
|
+
require 'action_view/template/error'
|
142
|
+
ActionView::MissingTemplate
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support/core_ext/array/wrap'
|
2
|
+
|
3
|
+
module Hydramata
|
4
|
+
module Works
|
5
|
+
# Responsible for coordinating the potentially complicated dom attributes
|
6
|
+
# for a given context.
|
7
|
+
module DomAttributesBuilder
|
8
|
+
module_function
|
9
|
+
# context - a data structure; provided as a placeholder; Maybe we could
|
10
|
+
# supply additional attributes based on the context
|
11
|
+
def call(context, attributes = {}, defaults = {})
|
12
|
+
returning_value = attributes.dup
|
13
|
+
defaults.each_pair do |key, value|
|
14
|
+
if returning_value.key?(key)
|
15
|
+
returning_value[key] = Array.wrap(returning_value[key]) + Array.wrap(value)
|
16
|
+
else
|
17
|
+
returning_value[key] = Array.wrap(value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
returning_value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'hydramata/works/conversions/presented_fieldsets'
|
2
|
+
require 'hydramata/works/base_presenter'
|
3
|
+
|
4
|
+
module Hydramata
|
5
|
+
module Works
|
6
|
+
# Responsible for coordinating the rendering of an in-memory Entity-like
|
7
|
+
# object to an output buffer.
|
8
|
+
class EntityPresenter < BasePresenter
|
9
|
+
include Conversions
|
10
|
+
|
11
|
+
attr_reader :presentation_structure, :presented_fieldset_builder
|
12
|
+
def initialize(collaborators = {})
|
13
|
+
entity = collaborators.fetch(:entity)
|
14
|
+
super(entity, collaborators)
|
15
|
+
@presentation_structure = collaborators.fetch(:presentation_structure) { default_presentation_structure }
|
16
|
+
@presented_fieldset_builder = collaborators.fetch(:presented_fieldset_builder) { default_presented_fieldset_builder }
|
17
|
+
end
|
18
|
+
|
19
|
+
def fieldsets
|
20
|
+
@fieldsets ||= presented_fieldset_builder.call(entity: self, presentation_structure: presentation_structure)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def default_dom_attributes
|
26
|
+
{
|
27
|
+
:class => [dom_class, presenter_dom_class],
|
28
|
+
:itemscope => true,
|
29
|
+
:itemtype => itemtype_schema_dot_org
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def presenter_dom_class
|
34
|
+
'work'
|
35
|
+
end
|
36
|
+
|
37
|
+
def view_path_slug_for_object
|
38
|
+
'works'
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_dom_class
|
42
|
+
work_type.to_s.downcase.gsub(/[\W_]+/, '-')
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_presented_fieldset_builder
|
46
|
+
->(collaborators) { PresentedFieldsets(collaborators) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_partial_prefixes
|
50
|
+
[
|
51
|
+
[TranslationKeyFragment(self)]
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_translation_scopes
|
56
|
+
[
|
57
|
+
['works', TranslationKeyFragment(self)]
|
58
|
+
]
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_presentation_structure
|
62
|
+
work_type
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|