Class: ROCrate::Preview
- Inherits:
-
File
- Object
- Entity
- DataEntity
- File
- ROCrate::Preview
- Defined in:
- lib/ro_crate/model/preview.rb
Overview
A representation of the ‘ro-crate-preview.html` file.
Constant Summary collapse
- IDENTIFIER =
'ro-crate-preview.html'.freeze
- DEFAULT_TEMPLATE =
::File.(::File.join(::File.dirname(__FILE__), '..', 'ro-crate-preview.html.erb'))
Instance Attribute Summary collapse
-
#template ⇒ String
The ERB template to use when rendering the preview.
Attributes inherited from Entity
Instance Method Summary collapse
-
#generate ⇒ String
Generate the crate’s ‘ro-crate-preview.html`.
-
#initialize(crate, properties = {}) ⇒ Preview
constructor
A new instance of Preview.
Methods inherited from File
Methods inherited from DataEntity
#entries, #filepath, format_id, specialize
Methods inherited from Entity
#==, #[], #[]=, #auto_dereference, #auto_reference, #canonical_id, #dereference, #eql?, #external?, format_id, #has_type?, #hash, #id, #id=, #inspect, properties, #raw_properties, #reference, #to_json, #type, #type=
Constructor Details
#initialize(crate, properties = {}) ⇒ Preview
Returns a new instance of Preview.
15 16 17 18 |
# File 'lib/ro_crate/model/preview.rb', line 15 def initialize(crate, properties = {}) @template = nil super(crate, nil, IDENTIFIER, properties) end |
Instance Attribute Details
#template ⇒ String
The ERB template to use when rendering the preview.
13 14 15 |
# File 'lib/ro_crate/model/preview.rb', line 13 def template @template end |
Instance Method Details
#generate ⇒ String
Generate the crate’s ‘ro-crate-preview.html`.
23 24 25 26 27 |
# File 'lib/ro_crate/model/preview.rb', line 23 def generate b = crate.get_binding renderer = ERB.new(template || ::File.read(DEFAULT_TEMPLATE)) renderer.result(b) end |