hydramata-works 0.0.1.prerelease

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.hound.yml +818 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +20 -0
  6. data/CONTRIBUTING.md +220 -0
  7. data/Gemfile +36 -0
  8. data/Guardfile +36 -0
  9. data/LICENSE +15 -0
  10. data/README.md +36 -0
  11. data/Rakefile +47 -0
  12. data/TODO.md +74 -0
  13. data/VISION.md +19 -0
  14. data/app/forms/hydramata/works/entity_form.rb +92 -0
  15. data/app/forms/hydramata/works/validation_service.rb +78 -0
  16. data/app/models/hydramata/works/data_definition.rb +57 -0
  17. data/app/models/hydramata/works/entities.rb +11 -0
  18. data/app/models/hydramata/works/entity.rb +75 -0
  19. data/app/models/hydramata/works/predicate.rb +35 -0
  20. data/app/models/hydramata/works/predicate_presentation_sequences/storage.rb +29 -0
  21. data/app/models/hydramata/works/predicate_set.rb +44 -0
  22. data/app/models/hydramata/works/predicate_sets/storage.rb +45 -0
  23. data/app/models/hydramata/works/predicates.rb +14 -0
  24. data/app/models/hydramata/works/predicates/storage.rb +33 -0
  25. data/app/models/hydramata/works/presentation_structure.rb +29 -0
  26. data/app/models/hydramata/works/property.rb +72 -0
  27. data/app/models/hydramata/works/property_set.rb +89 -0
  28. data/app/models/hydramata/works/validations.rb +6 -0
  29. data/app/models/hydramata/works/value.rb +34 -0
  30. data/app/models/hydramata/works/work_type.rb +49 -0
  31. data/app/models/hydramata/works/work_types.rb +14 -0
  32. data/app/models/hydramata/works/work_types/storage.rb +42 -0
  33. data/app/parsers/hydramata/works/datastream_parser.rb +36 -0
  34. data/app/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser.rb +60 -0
  35. data/app/parsers/hydramata/works/datastream_parsers/simple_xml_parser.rb +27 -0
  36. data/app/parsers/hydramata/works/predicate_parser.rb +31 -0
  37. data/app/parsers/hydramata/works/predicate_parsers/simple_parser.rb +13 -0
  38. data/app/parsers/hydramata/works/validations_parser.rb +22 -0
  39. data/app/parsers/hydramata/works/value_parser.rb +26 -0
  40. data/app/parsers/hydramata/works/value_parsers.rb +27 -0
  41. data/app/parsers/hydramata/works/value_parsers/date_parser.rb +13 -0
  42. data/app/parsers/hydramata/works/value_parsers/interrogation_parser.rb +18 -0
  43. data/app/parsers/hydramata/works/value_parsers/simple_parser.rb +14 -0
  44. data/app/presenters/hydramata/works/base_presenter.rb +146 -0
  45. data/app/presenters/hydramata/works/dom_attributes_builder.rb +24 -0
  46. data/app/presenters/hydramata/works/entity_presenter.rb +67 -0
  47. data/app/presenters/hydramata/works/fieldset_presenter.rb +54 -0
  48. data/app/presenters/hydramata/works/property_presenter.rb +51 -0
  49. data/app/presenters/hydramata/works/value_presenter.rb +60 -0
  50. data/app/renderers/hydramata/works/entity_renderer.rb +45 -0
  51. data/app/views/hydramata/works/fieldsets/_edit.html.erb +4 -0
  52. data/app/views/hydramata/works/fieldsets/_show.html.erb +8 -0
  53. data/app/views/hydramata/works/fieldsets/_show.json.jbuilder +8 -0
  54. data/app/views/hydramata/works/properties/_edit.html.erb +12 -0
  55. data/app/views/hydramata/works/properties/_show.html.erb +3 -0
  56. data/app/views/hydramata/works/properties/_show.json.jbuilder +1 -0
  57. data/app/views/hydramata/works/works/_edit.html.erb +8 -0
  58. data/app/views/hydramata/works/works/_new.html.erb +8 -0
  59. data/app/views/hydramata/works/works/_show.html.erb +3 -0
  60. data/app/views/hydramata/works/works/_show.json.jbuilder +13 -0
  61. data/app/wranglers/hydramata/works/fedora_wrangler.rb +66 -0
  62. data/bin/rails +12 -0
  63. data/db/migrate/20140606132349_create_hydramata_work_predicates.rb +13 -0
  64. data/db/migrate/20140606132350_create_hydramata_work_types.rb +9 -0
  65. data/db/migrate/20140606132351_create_hydramata_work_predicate_sets.rb +13 -0
  66. data/db/migrate/20140606132352_create_hydramata_work_predicate_presentation_sequences.rb +12 -0
  67. data/db/migrate/20140623200635_add_validations_to_predicates.rb +5 -0
  68. data/db/migrate/20140627134133_adding_item_type_schema_dot_org_to_work_type.rb +5 -0
  69. data/db/migrate/20140627140840_adding_item_prop_schema_dot_org_to_predicate.rb +5 -0
  70. data/db/seeds.rb +36 -0
  71. data/documents/administrative-set-strawperson.md +45 -0
  72. data/documents/diagrams/hydramata-refactor-tasks.dot +88 -0
  73. data/documents/diagrams/hydramata-sip-dip-aip.dot +88 -0
  74. data/documents/diagrams/hydramata-work-architecture.dot +129 -0
  75. data/documents/diagrams/hydramata-work-subcomponents.dot +36 -0
  76. data/documents/diagrams/map-from-database-to-work-object.dot +44 -0
  77. data/documents/diagrams/map-from-fedora-to-work-object.dot +51 -0
  78. data/documents/diagrams/map-from-input-to-work-object.dot +37 -0
  79. data/documents/diagrams/map-from-work-object-to-database.dot +31 -0
  80. data/documents/diagrams/work-rendering.dot +53 -0
  81. data/documents/diagrams/work-structure.dot +32 -0
  82. data/documents/handling-work.md +224 -0
  83. data/documents/high-level-stories.md +105 -0
  84. data/documents/hydramata-components.md +82 -0
  85. data/documents/interface-between-work-and-permissions.md +131 -0
  86. data/documents/interface-between-work-and-workflow.md +6 -0
  87. data/documents/timeline.md +75 -0
  88. data/fs +3 -0
  89. data/gemfiles/rails4.1.gemfile +12 -0
  90. data/gemfiles/rails4.gemfile +13 -0
  91. data/hydramata-works.gemspec +43 -0
  92. data/lib/hydramata-works.rb +23 -0
  93. data/lib/hydramata/works/conversions.rb +21 -0
  94. data/lib/hydramata/works/conversions/exceptions.rb +18 -0
  95. data/lib/hydramata/works/conversions/predicate.rb +22 -0
  96. data/lib/hydramata/works/conversions/predicate_set.rb +28 -0
  97. data/lib/hydramata/works/conversions/presented_fieldsets.rb +28 -0
  98. data/lib/hydramata/works/conversions/presenter.rb +13 -0
  99. data/lib/hydramata/works/conversions/property.rb +31 -0
  100. data/lib/hydramata/works/conversions/property_set.rb +23 -0
  101. data/lib/hydramata/works/conversions/translation_key_fragment.rb +20 -0
  102. data/lib/hydramata/works/conversions/value.rb +20 -0
  103. data/lib/hydramata/works/conversions/work_type.rb +26 -0
  104. data/lib/hydramata/works/engine.rb +31 -0
  105. data/lib/hydramata/works/linters.rb +99 -0
  106. data/lib/hydramata/works/linters/implement_data_definition_interface_matcher.rb +17 -0
  107. data/lib/hydramata/works/linters/implement_entity_interface_matcher.rb +16 -0
  108. data/lib/hydramata/works/linters/implement_predicate_interface_matcher.rb +17 -0
  109. data/lib/hydramata/works/linters/implement_predicate_set_interface_matcher.rb +8 -0
  110. data/lib/hydramata/works/linters/implement_property_set_interface_matcher.rb +8 -0
  111. data/lib/hydramata/works/linters/implement_value_interface_matcher.rb +8 -0
  112. data/lib/hydramata/works/linters/implement_work_type_interface_matcher.rb +13 -0
  113. data/lib/hydramata/works/linters/interface_matcher_builder.rb +36 -0
  114. data/lib/hydramata/works/translator.rb +67 -0
  115. data/lib/hydramata/works/version.rb +5 -0
  116. data/lib/hydramata_works.rb +2 -0
  117. data/lib/tasks/hydramata_work_tasks.rake +4 -0
  118. data/run_each_spec_in_isolation +16 -0
  119. data/run_each_spec_in_isolation.txt +110 -0
  120. data/script/analyzer.rb +124 -0
  121. data/script/fast_specs +22 -0
  122. data/spec/features/fedora_to_in_memory_spec.rb +60 -0
  123. data/spec/features/format_and_view_path_overrides_spec.rb +72 -0
  124. data/spec/features/in_memory_to_output_buffer_spec.rb +109 -0
  125. data/spec/features/instantiate_entity_from_persisted_work_type_spec.rb +26 -0
  126. data/spec/features/new_user_input_to_in_memory_spec.rb +75 -0
  127. data/spec/features/translation_services_spec.rb +107 -0
  128. data/spec/features/validate_entity_based_on_work_type_structure_spec.rb +19 -0
  129. data/spec/fixtures/cassettes/fedora-object.yml +299 -0
  130. data/spec/fixtures/translations.yml +20 -0
  131. data/spec/forms/hydramata/works/entity_form_spec.rb +83 -0
  132. data/spec/forms/hydramata/works/validation_service_spec.rb +32 -0
  133. data/spec/lib/hydramata-work_spec.rb +14 -0
  134. data/spec/lib/hydramata/works/conversions/predicate_set_spec.rb +50 -0
  135. data/spec/lib/hydramata/works/conversions/predicate_spec.rb +43 -0
  136. data/spec/lib/hydramata/works/conversions/presented_fieldsets_spec.rb +52 -0
  137. data/spec/lib/hydramata/works/conversions/presenter_spec.rb +22 -0
  138. data/spec/lib/hydramata/works/conversions/property_set_spec.rb +42 -0
  139. data/spec/lib/hydramata/works/conversions/property_spec.rb +68 -0
  140. data/spec/lib/hydramata/works/conversions/translation_key_fragment_spec.rb +45 -0
  141. data/spec/lib/hydramata/works/conversions/value_spec.rb +36 -0
  142. data/spec/lib/hydramata/works/conversions/work_type_spec.rb +55 -0
  143. data/spec/lib/hydramata/works/translator_spec.rb +81 -0
  144. data/spec/models/hydramata/works/data_definition_spec.rb +53 -0
  145. data/spec/models/hydramata/works/entity_spec.rb +50 -0
  146. data/spec/models/hydramata/works/predicate_presentation_sequences/storage_spec.rb +15 -0
  147. data/spec/models/hydramata/works/predicate_set_spec.rb +63 -0
  148. data/spec/models/hydramata/works/predicate_sets/storage_spec.rb +37 -0
  149. data/spec/models/hydramata/works/predicate_spec.rb +16 -0
  150. data/spec/models/hydramata/works/predicates/storage_spec.rb +78 -0
  151. data/spec/models/hydramata/works/predicates_spec.rb +18 -0
  152. data/spec/models/hydramata/works/presentation_structure_spec.rb +27 -0
  153. data/spec/models/hydramata/works/property_set_spec.rb +135 -0
  154. data/spec/models/hydramata/works/property_spec.rb +74 -0
  155. data/spec/models/hydramata/works/value_spec.rb +61 -0
  156. data/spec/models/hydramata/works/work_type_spec.rb +45 -0
  157. data/spec/models/hydramata/works/work_types/storage_spec.rb +74 -0
  158. data/spec/models/hydramata/works/work_types_spec.rb +16 -0
  159. data/spec/parsers/hydramata/works/datastream_parser_spec.rb +29 -0
  160. data/spec/parsers/hydramata/works/datastream_parsers/rdf_ntriples_parser_spec.rb +65 -0
  161. data/spec/parsers/hydramata/works/datastream_parsers/simple_xml_parser_spec.rb +37 -0
  162. data/spec/parsers/hydramata/works/predicate_parser_spec.rb +30 -0
  163. data/spec/parsers/hydramata/works/predicate_parsers/simple_parser_spec.rb +20 -0
  164. data/spec/parsers/hydramata/works/validations_parser_spec.rb +31 -0
  165. data/spec/parsers/hydramata/works/value_parser_spec.rb +22 -0
  166. data/spec/parsers/hydramata/works/value_parsers/simple_parser_spec.rb +20 -0
  167. data/spec/parsers/hydramata/works/value_parsers_spec.rb +36 -0
  168. data/spec/presenters/hydramata/works/base_presenter_spec.rb +111 -0
  169. data/spec/presenters/hydramata/works/dom_attributes_builder_spec.rb +26 -0
  170. data/spec/presenters/hydramata/works/entity_presenter_spec.rb +51 -0
  171. data/spec/presenters/hydramata/works/fieldset_presenter_spec.rb +58 -0
  172. data/spec/presenters/hydramata/works/property_presenter_spec.rb +42 -0
  173. data/spec/presenters/hydramata/works/value_presenter_spec.rb +49 -0
  174. data/spec/renderers/hydramata/works/entity_renderer_spec.rb +25 -0
  175. data/spec/spec_active_record_helper.rb +30 -0
  176. data/spec/spec_fast_helper.rb +12 -0
  177. data/spec/spec_slow_helper.rb +56 -0
  178. data/spec/spec_view_helper.rb +14 -0
  179. data/spec/test_app_templates/lib/generators/test_app_generator.rb +21 -0
  180. data/spec/views/hydramata/works/fieldsets/_edit.html.erb_spec.rb +29 -0
  181. data/spec/views/hydramata/works/fieldsets/_show.html.erb_spec.rb +25 -0
  182. data/spec/views/hydramata/works/properties/_edit.html.erb_spec.rb +22 -0
  183. data/spec/views/hydramata/works/properties/_show.html.erb_spec.rb +22 -0
  184. data/spec/views/hydramata/works/works/_edit.html.erb_spec.rb +23 -0
  185. data/spec/views/hydramata/works/works/_new.html.erb_spec.rb +23 -0
  186. data/spec/views/hydramata/works/works/_show.html.erb_spec.rb +24 -0
  187. data/spec/wranglers/hydramata/works/fedora_wrangler_spec.rb +26 -0
  188. 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,13 @@
1
+ module Hydramata
2
+ module Works
3
+ module PredicateParsers
4
+ # A comically simple parser. You get what you give.
5
+ module SimpleParser
6
+ module_function
7
+ def call(object, &block)
8
+ block.call(value: object)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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,13 @@
1
+ module Hydramata
2
+ module Works
3
+ module ValueParsers
4
+ module DateParser
5
+ module_function
6
+ def call(object, &block)
7
+ date = Date.parse(object.to_s)
8
+ block.call(value: date, raw_object: object)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ 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