Class: MarkdownRecord::Rendering::Nodes::JsonBase

Inherits:
Object
  • Object
show all
Includes:
ContentDsl, PathUtilities
Defined in:
lib/markdown_record/rendering/nodes/json_base.rb

Direct Known Subclasses

JsonDirectory, JsonFile

Constant Summary

Constants included from ContentDsl

ContentDsl::HTML_COMMENT_REGEX

Constants included from ContentDsl::Enable

ContentDsl::Enable::ENCODED_REGEX, ContentDsl::Enable::REGEX

Constants included from ContentDsl::Disable

ContentDsl::Disable::ENCODED_REGEX, ContentDsl::Disable::REGEX

Constants included from ContentDsl::UseLayout

ContentDsl::UseLayout::ENCODED_REGEX, ContentDsl::UseLayout::REGEX

Constants included from ContentDsl::Fragment

ContentDsl::Fragment::ENCODED_REGEX, ContentDsl::Fragment::REGEX

Constants included from ContentDsl::DirectoryFragment

ContentDsl::DirectoryFragment::ENCODED_REGEX, ContentDsl::DirectoryFragment::REGEX

Constants included from ContentDsl::EndModel

ContentDsl::EndModel::ENCODED_REGEX, ContentDsl::EndModel::REGEX

Constants included from ContentDsl::EndAttribute

ContentDsl::EndAttribute::ENCODED_REGEX, ContentDsl::EndAttribute::REGEX

Constants included from ContentDsl::Attribute

ContentDsl::Attribute::ENCODED_REGEX, ContentDsl::Attribute::REGEX

Constants included from ContentDsl::Model

ContentDsl::Model::ENCODED_REGEX, ContentDsl::Model::REGEX

Constants included from ContentDsl::Scope

ContentDsl::Scope::ENCODED_REGEX, ContentDsl::Scope::REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContentDsl

#remove_html_dsl_command, #remove_json_dsl_commands

Methods included from ContentDsl::Enable

#enable_dsl, remove_dsl

Methods included from ContentDsl::Disable

#disable_dsl, remove_dsl

Methods included from ContentDsl::UseLayout

remove_dsl, #use_layout_dsl

Methods included from ContentDsl::Fragment

#fragment_dsl, remove_dsl

Methods included from ContentDsl::DirectoryFragment

#directory_fragment_dsl, remove_dsl

Methods included from ContentDsl::EndModel

#end_model_dsl, remove_dsl

Methods included from ContentDsl::EndAttribute

#end_attribute_dsl, remove_dsl

Methods included from ContentDsl::Attribute

#attribute_dsl, remove_dsl

Methods included from ContentDsl::Model

#model_dsl, remove_dsl

Methods included from ContentDsl::Scope

remove_dsl, #scope_dsl

Methods included from PathUtilities

#base_content_root_name, #base_rendered_path, #base_rendered_root, #clean_path, #erb_locals_from_path, #fragment_attributes_from_path, #full_path_to_parts, #path_to_fragment_id, #remove_prefix, #rendered_path, #scoped_id_to_parts, #to_scoped_id

Constructor Details

#initialize(pathname, options) ⇒ JsonBase

Returns a new instance of JsonBase.



12
13
14
15
16
17
18
19
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 12

def initialize(pathname, options)
  @pathname = pathname
  @options = options
  @name = @pathname.relative_path_from(MarkdownRecord.config.content_root.parent).to_s
  @json_models = {}
  @concatenated = nil
  @scope = nil
end

Instance Attribute Details

#concatenatedObject (readonly)

Returns the value of attribute concatenated.



10
11
12
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 10

def concatenated
  @concatenated
end

#json_modelsObject (readonly)

Returns the value of attribute json_models.



9
10
11
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 9

def json_models
  @json_models
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 8

def name
  @name
end

Instance Method Details

#add_content_fragmentObject



36
37
38
39
40
41
42
43
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 36

def add_content_fragment
  return unless @options[:render_content_fragment_json]

  content_fragment_hash = fragment_attributes_from_path(name).merge("meta" => fragment_meta, "concatenated" => concatenated, "__scope__" => scope)
  
  @json_models["markdown_record/content_fragment"] ||= []
  @json_models["markdown_record/content_fragment"] << content_fragment_hash
end

#fragment_metaObject



27
28
29
30
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 27

def fragment_meta
  # This method defines an interface and should be overridden by a subclass.
  {}
end

#render(file_saver, inherited_scope = nil) ⇒ Object



21
22
23
24
25
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 21

def render(file_saver, inherited_scope = nil)
  # This method defines an interface and should be overridden by a subclass.
  add_content_fragment
  save(file_saver)
end

#save(file_saver) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 45

def save(file_saver)
  fragments = @json_models.slice("markdown_record/content_fragment")
  non_fragments = @json_models.except("markdown_record/content_fragment")
  path = clean_path(@name)
  file_saver.save_to_file(non_fragments.to_json, "#{path}.json", @options)
  file_saver.save_to_file(fragments.to_json, "#{path}.json", @options, true)
end

#scopeObject



32
33
34
# File 'lib/markdown_record/rendering/nodes/json_base.rb', line 32

def scope
  @scope
end