markdown_record 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +63 -43
  3. data/app/helpers/markdown_record/application_helper.rb +23 -0
  4. data/app/helpers/markdown_record/controller_helpers.rb +1 -1
  5. data/app/helpers/markdown_record/view_helpers.rb +9 -3
  6. data/{lib → app/models}/markdown_record/base.rb +10 -0
  7. data/{lib → app/models}/markdown_record/content_fragment.rb +17 -2
  8. data/lib/generators/markdown_record_generator.rb +6 -0
  9. data/lib/markdown_record/configuration.rb +4 -0
  10. data/lib/markdown_record/file_sorting/base.rb +25 -0
  11. data/lib/markdown_record/file_sorting/date_sorter.rb +14 -0
  12. data/lib/markdown_record/file_sorting/sem_ver_sorter.rb +47 -0
  13. data/lib/markdown_record/{association.rb → models/association.rb} +20 -3
  14. data/lib/markdown_record/{associations.rb → models/associations.rb} +17 -9
  15. data/lib/markdown_record/{content_associations.rb → models/content_associations.rb} +4 -2
  16. data/lib/markdown_record/models/filtering.rb +13 -0
  17. data/lib/markdown_record/models/filters/array_filter.rb +11 -0
  18. data/lib/markdown_record/models/filters/base_filter.rb +35 -0
  19. data/lib/markdown_record/models/filters/hash_filter.rb +81 -0
  20. data/lib/markdown_record/models/filters/nil_filter.rb +11 -0
  21. data/lib/markdown_record/models/filters/range_filter.rb +11 -0
  22. data/lib/markdown_record/models/filters/regexp_filter.rb +11 -0
  23. data/lib/markdown_record/models/filters/symbol_filter.rb +14 -0
  24. data/lib/markdown_record/models/filters.rb +22 -0
  25. data/lib/markdown_record/models/model_inflator.rb +65 -0
  26. data/lib/markdown_record/path_utilities.rb +20 -11
  27. data/lib/markdown_record/rendering/content_dsl/attribute.rb +22 -0
  28. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/directory_fragment.rb +3 -3
  29. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/disable.rb +2 -2
  30. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/enable.rb +2 -2
  31. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/end_attribute.rb +3 -3
  32. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/end_model.rb +3 -3
  33. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/fragment.rb +3 -3
  34. data/lib/markdown_record/rendering/content_dsl/model.rb +22 -0
  35. data/lib/markdown_record/rendering/content_dsl/scope.rb +22 -0
  36. data/lib/markdown_record/{content_dsl → rendering/content_dsl}/use_layout.rb +3 -3
  37. data/lib/markdown_record/rendering/content_dsl.rb +45 -0
  38. data/lib/markdown_record/rendering/html_renderer.rb +22 -0
  39. data/lib/markdown_record/{indexer.rb → rendering/indexer.rb} +0 -10
  40. data/lib/markdown_record/rendering/json_renderer.rb +20 -0
  41. data/lib/markdown_record/rendering/nodes/html_base.rb +95 -0
  42. data/lib/markdown_record/rendering/nodes/html_directory.rb +51 -0
  43. data/lib/markdown_record/rendering/nodes/html_file.rb +48 -0
  44. data/lib/markdown_record/rendering/nodes/json_base.rb +55 -0
  45. data/lib/markdown_record/rendering/nodes/json_directory.rb +69 -0
  46. data/lib/markdown_record/rendering/nodes/json_file.rb +172 -0
  47. data/lib/markdown_record/{rendering.rb → rendering/rendering.rb} +1 -1
  48. data/lib/markdown_record/{validator.rb → rendering/validator.rb} +4 -4
  49. data/lib/markdown_record/version.rb +1 -1
  50. data/lib/markdown_record.rb +21 -14
  51. data/templates/demo/content/10_custom_models_and_associations.md.erb +27 -7
  52. data/templates/demo/content/11_controller_helpers.md.erb +2 -2
  53. data/templates/demo/content/12_configuration.md.erb +22 -3
  54. data/templates/demo/content/13_sandbox/1_foo.md +2 -1
  55. data/templates/demo/content/13_sandbox/2_sandbox_nested/1_bar.md +4 -1
  56. data/templates/demo/content/1_home.md.erb +30 -13
  57. data/templates/demo/content/2_installation.md.erb +61 -46
  58. data/templates/demo/content/3_rendering_basics.md.erb +3 -3
  59. data/templates/demo/content/4_content_dsl.md.erb +22 -11
  60. data/templates/demo/content/5_routes.md.erb +10 -7
  61. data/templates/demo/content/6_model_basics.md.erb +11 -11
  62. data/templates/demo/content/7_content_frags.md.erb +9 -6
  63. data/templates/demo/content/8_erb_syntax_and_view_helpers.md.erb +32 -11
  64. data/templates/demo/content/9_layouts.md.erb +3 -3
  65. data/templates/demo/layouts/_global_layout.html.erb +1 -0
  66. data/templates/demo/models/dsl_command.rb +6 -0
  67. data/templates/demo/models/section.rb +5 -0
  68. data/templates/render_content.thor +2 -1
  69. data/templates/tests/assets/images/ruby-logo.png +0 -0
  70. data/templates/tests/content/1_test_files_home.md.erb +31 -0
  71. data/templates/tests/content/2_content_dsl_tests/1_content_dsl.md.erb +162 -0
  72. data/templates/tests/content/2_content_dsl_tests/2_nested_directory/1_associations.md.erb +83 -0
  73. data/templates/tests/layouts/_concatenated_layout.html.erb +12 -0
  74. data/templates/tests/layouts/_custom_layout.html.erb +14 -0
  75. data/templates/tests/layouts/_file_layout.html.erb +15 -0
  76. data/templates/tests/layouts/_global_layout.html.erb +116 -0
  77. metadata +53 -34
  78. data/app/models/markdown_record/demo/dsl_command.rb +0 -10
  79. data/app/models/markdown_record/demo/section.rb +0 -9
  80. data/app/models/markdown_record/tests/child_model.rb +0 -15
  81. data/app/models/markdown_record/tests/fake_active_record_model.rb +0 -13
  82. data/app/models/markdown_record/tests/model.rb +0 -15
  83. data/app/models/markdown_record/tests/other_child_model.rb +0 -15
  84. data/lib/markdown_record/cli.rb +0 -54
  85. data/lib/markdown_record/content_dsl/attribute.rb +0 -22
  86. data/lib/markdown_record/content_dsl/model.rb +0 -23
  87. data/lib/markdown_record/content_dsl/render_format.rb +0 -22
  88. data/lib/markdown_record/content_dsl/render_strategy.rb +0 -22
  89. data/lib/markdown_record/content_dsl.rb +0 -37
  90. data/lib/markdown_record/html_renderer.rb +0 -194
  91. data/lib/markdown_record/json_renderer.rb +0 -270
  92. data/lib/markdown_record/model_inflator.rb +0 -107
  93. data/lib/markdown_record/routes_renderer.rb +0 -0
  94. /data/lib/markdown_record/{file_saver.rb → rendering/file_saver.rb} +0 -0
@@ -1,4 +1,5 @@
1
- <!--directory_fragment { "author": "You", "name": "Sandbox", "parent_id": "content/home" } -->
1
+ <!--directory_fragment { "author": "You", "name": "Sandbox", "relative_parent_id": "home" } -->
2
+ <!--fragment { "name": "Foo", "author": "You" } -->
2
3
  <!--use_layout:_custom_layout.html.erb-->
3
4
 
4
5
  Feel free to use this directory as a sandbox to experiment with the things you learn from the guide, without fear of messing up the guide itself. The things defined here are used for automated tests only, so feel free to delete/alter anything you want here.
@@ -1,4 +1,5 @@
1
- <!--directory_fragment { "author": "You", "name": "Sandbox", "parent_id": "content/sandbox/foo" } -->
1
+ <!--directory_fragment { "author": "You", "name": "Sandbox", "relative_parent_id": "../foo" } -->
2
+ <!--fragment { "name": "Bar", "author": "You" } -->
2
3
  <!--use_layout:_custom_layout.html.erb-->
3
4
 
4
5
  Feel free to use this directory as a sandbox to experiment with the things you learn from the guide, without fear of messing up the guide itself. The things defined here are used for automated tests only, so feel free to delete/alter anything you want here.
@@ -7,6 +8,8 @@ When you are done experimenting and want to start creating for real, feel free t
7
8
 
8
9
  *Note: you will need to add the .erb extension to this file to use ERB syntax in it.*
9
10
 
11
+ Notice how this file's *parent* is `foo`. This is set using the `fragment` DSL command.
12
+
10
13
  <!--model { "id": 1, "type": "markdown_record/tests/child_model", "model_id": 1, "string_field": "hey", "int_field": 100, "float_field": 95.5, "bool_field": true, "date_field": "03/13/2023", "maybe_field": null, "hash_field": {} }-->
11
14
 
12
15
  <!--model { "id": 2, "type": "markdown_record/tests/child_model", "model_id": 1, "string_field": "asdf", "int_field": 333, "float_field": 10.5, "bool_field": false, "date_field": "01/01/2000", "maybe_field": 7, "hash_field": {} }-->
@@ -1,18 +1,22 @@
1
1
  <!--directory_fragment { "name": "Demo", "author": "Bryant Morrill" } -->
2
2
  <!--fragment { "name": "Home", "author": "Bryant Morrill" } -->
3
3
 
4
+ <!--model {"type": "version", "id": "1"}-->
5
+
4
6
  # MarkdownRecord
5
7
 
6
8
  Welcome to MarkdownRecord!
7
9
 
8
10
  This document will walk you through the many powerful features of MarkdownRecord, and is created with MarkdownRecord itself. Hopefully, you are rendering this page locally from your own application, and will be able to get a peak under the hood to see how it all works by looking directly at the source markdown files.
9
11
 
10
- If you haven't installed it locally yet, you can find instructions <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/installation"), "here") %>.
12
+ If you haven't installed it locally yet, you can find instructions <%= link_to_markdown_record(fragment.find_relative("installation"), "here") %>.
11
13
 
12
14
  After following the installation guide, you should see a `markdown_record` folder inside your application root. This folder contains three subdirectories: `content`, `layouts` and `rendered`.
13
15
 
14
16
  Feel free to poke around and explore the files in the directories mentioned above as you go through this guide. They will serve as a great reference to help make sense of the features and concepts described here.
15
17
 
18
+ You can find the hosted version of these docs [here](https://markdown-record-docs.herokuapp.com/).
19
+
16
20
  ## Workflow
17
21
 
18
22
  The general workflow while using MarkdownRecord, once installed in your application, is as follows:
@@ -23,18 +27,31 @@ The general workflow while using MarkdownRecord, once installed in your applicat
23
27
  4. Use the provided view helpers to link to the rendered content in your application's views, relying only on the controllers provided by the engine for serving the content if you wish.
24
28
  5. Use model classes inheriting from `MarkdownRecord::Base` to interact with your html and json rendered content, taking advantage of the associations you can define manually as well a the automatic associations they have based on content location.
25
29
 
26
- The next step is to read through the <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/rendering_basics"), "Rendering Basics") %> section to understand the basic rendering process of markdown source content into HTML and JSON.
30
+ The next step is to read through the <%= link_to_markdown_record(fragment.find_relative("rendering_basics"), "Rendering Basics") %> section to understand the basic rendering process of markdown source content into HTML and JSON.
27
31
 
28
32
  The following links will take you to other sections of this guide. Each section builds upon the last, so it is recommended to read through them in order if you are new to MarkdownRecord.
29
33
 
30
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/content_dsl"))%>
31
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/routes")) %>
32
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/model_basics")) %>
33
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/content_frags")) %>
34
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/erb_syntax_and_view_helpers")) %>
35
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/layouts")) %>
36
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/custom_models_and_associations")) %>
37
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/controller_helpers")) %>
38
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/configuration")) %>
39
- - <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/sandbox")) %>
40
-
34
+ - <%= link_to_markdown_record(fragment.find_relative("content_dsl"))%>
35
+ - <%= link_to_markdown_record(fragment.find_relative("routes")) %>
36
+ - <%= link_to_markdown_record(fragment.find_relative("model_basics")) %>
37
+ - <%= link_to_markdown_record(fragment.find_relative("content_frags")) %>
38
+ - <%= link_to_markdown_record(fragment.find_relative("erb_syntax_and_view_helpers")) %>
39
+ - <%= link_to_markdown_record(fragment.find_relative("layouts")) %>
40
+ - <%= link_to_markdown_record(fragment.find_relative("custom_models_and_associations")) %>
41
+ - <%= link_to_markdown_record(fragment.find_relative("controller_helpers")) %>
42
+ - <%= link_to_markdown_record(fragment.find_relative("configuration")) %>
43
+ - <%= link_to_markdown_record(fragment.find_relative("sandbox")) %>
44
+
45
+ ## 0.1.4 Release Notes
46
+
47
+ Version 0.1.4 is the second beta version to be published and is packed with tons of big improvements. This is the first version that is really usable. Changes since 0.1.3 are as follows:
48
+
49
+ - Added rendering scopes to isolate models within scopes, allowing reuse of ids, etc.
50
+ - View helper quality of life changes - chaining url and path helpers onto `main_app` is no longer necessary.
51
+ - Added a new `render_fragment` view helper.
52
+ - Made MarkdownRecord models compatible with the Rails `dom_id` view helper.
53
+ - Made view helper links use the id basename for Content Fragments by default (if no other text is provided) if the `meta[:name]` field isn't set.
54
+ - Allow setting the `relative_parent_id` for content fragments, which overrides the `parent` just like `parent_id` but with a relative id.
55
+ - Added `find_relative` method on `MarkdownRecord::ContentFragment`.
56
+ - Greatly enhanced file sorting and numeric prefix options, so that prefixing files with dates or semantic versions is now possible.
57
+ - HUGE refactors and code improvements behind the scenes. Sandi Metz would be proud.
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "name": "Installation", "parent_id": "content/home" } -->
2
- <!--model { "type": "markdown_record/demo/section", "id": 1, "name": "Installation" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "name": "Installation", "relative_parent_id": "home" } -->
2
+ <!--model { "type": "section", "id": 1, "name": "Installation" } -->
3
3
 
4
4
  # Installation
5
5
 
@@ -31,30 +31,36 @@ The above command will install the engine, resulting in the following output and
31
31
  create markdown_record/content
32
32
  create markdown_record/layouts
33
33
  create markdown_record/rendered
34
+ exist app/models
35
+ identical app/models/dsl_command.rb
36
+ identical app/models/section.rb
34
37
  exist markdown_record/content
35
- create markdown_record/content/controller_helpers.md.erb
36
- create markdown_record/content/configuration.md.erb
37
- create markdown_record/content/sandbox/foo.md
38
- create markdown_record/content/home.md.erb
39
- create markdown_record/content/installation.md.erb
40
- create markdown_record/content/rendering_basics.md.erb
41
- create markdown_record/content/content_dsl.md.erb
42
- create markdown_record/content/routes.md.erb
43
- create markdown_record/content/model_basics.md.erb
44
- create markdown_record/content/content_frags.md.erb
45
- create markdown_record/content/erb_syntax_and_view_helpers.md.erb
46
- create markdown_record/content/custom_models_and_associations.md.erb
47
- exist markdown_record/layouts
38
+ create markdown_record/content/10_custom_models_and_associations.md.erb
39
+ create markdown_record/content/11_controller_helpers.md.erb
40
+ create markdown_record/content/12_configuration.md.erb
41
+ create markdown_record/content/13_sandbox/1_foo.md
42
+ create markdown_record/content/13_sandbox/2_sandbox_nested/1_bar.md
43
+ create markdown_record/content/1_home.md.erb
44
+ create markdown_record/content/2_installation.md.erb
45
+ create markdown_record/content/3_rendering_basics.md.erb
46
+ create markdown_record/content/4_content_dsl.md.erb
47
+ create markdown_record/content/5_routes.md.erb
48
+ create markdown_record/content/6_model_basics.md.erb
49
+ create markdown_record/content/7_content_frags.md.erb
50
+ create markdown_record/content/8_erb_syntax_and_view_helpers.md.erb
51
+ create markdown_record/content/9_layouts.md.erb
52
+ exist markdown_record/layouts
48
53
  create markdown_record/layouts/_concatenated_layout.html.erb
49
54
  create markdown_record/layouts/_custom_layout.html.erb
50
55
  create markdown_record/layouts/_file_layout.html.erb
51
56
  create markdown_record/layouts/_global_layout.html.erb
52
- create app/assets/images
57
+ exist app/assets/images
53
58
  create app/assets/images/ruby-logo.png
54
59
  create config/initializers/markdown_record.rb
55
60
  create Thorfile
56
61
  create lib/tasks/render_content.thor
57
62
  gsub config/routes.rb
63
+ gsub config/routes.rb
58
64
  ```
59
65
 
60
66
  The files and folders inside `markdown_record/content` are for demo purposes only, and can be deleted once you are ready to create your own content.
@@ -77,53 +83,62 @@ You should see the following output:
77
83
 
78
84
  ```bash
79
85
  ---------------------------------------------------------------
80
- rendering html and json content with options {:concat=>true, :deep=>true, :save=>true, :layout=>"_concatenated_layout.html.erb", :render_content_fragment_json=>true} ...
86
+ rendering html and json content with options {:concat=>true, :deep=>true, :save=>true, :render_content_fragment_json=>true} ...
81
87
  ---------------------------------------------------------------
82
88
  rendered: /markdown_record/rendered/content_fragments.json
83
89
  rendered: /markdown_record/rendered/content.json
84
- rendered: /markdown_record/rendered/content/custom_models_and_associations_fragments.json
85
- rendered: /markdown_record/rendered/content/custom_models_and_associations.json
86
- rendered: /markdown_record/rendered/content/erb_syntax_and_view_helpers_fragments.json
87
- rendered: /markdown_record/rendered/content/erb_syntax_and_view_helpers.json
88
- rendered: /markdown_record/rendered/content/content_frags_fragments.json
89
- rendered: /markdown_record/rendered/content/content_frags.json
90
- rendered: /markdown_record/rendered/content/model_basics_fragments.json
91
- rendered: /markdown_record/rendered/content/model_basics.json
92
- rendered: /markdown_record/rendered/content/routes_fragments.json
93
- rendered: /markdown_record/rendered/content/routes.json
94
- rendered: /markdown_record/rendered/content/content_dsl_fragments.json
95
- rendered: /markdown_record/rendered/content/content_dsl.json
96
90
  rendered: /markdown_record/rendered/content/rendering_basics_fragments.json
97
91
  rendered: /markdown_record/rendered/content/rendering_basics.json
98
- rendered: /markdown_record/rendered/content/installation_fragments.json
99
- rendered: /markdown_record/rendered/content/installation.json
100
92
  rendered: /markdown_record/rendered/content/home_fragments.json
101
93
  rendered: /markdown_record/rendered/content/home.json
94
+ rendered: /markdown_record/rendered/content/controller_helpers_fragments.json
95
+ rendered: /markdown_record/rendered/content/controller_helpers.json
96
+ rendered: /markdown_record/rendered/content/erb_syntax_and_view_helpers_fragments.json
97
+ rendered: /markdown_record/rendered/content/erb_syntax_and_view_helpers.json
98
+ rendered: /markdown_record/rendered/content/layouts_fragments.json
99
+ rendered: /markdown_record/rendered/content/layouts.json
100
+ rendered: /markdown_record/rendered/content/configuration_fragments.json
101
+ rendered: /markdown_record/rendered/content/configuration.json
102
102
  rendered: /markdown_record/rendered/content/sandbox_fragments.json
103
103
  rendered: /markdown_record/rendered/content/sandbox.json
104
+ rendered: /markdown_record/rendered/content/sandbox/sandbox_nested_fragments.json
105
+ rendered: /markdown_record/rendered/content/sandbox/sandbox_nested.json
106
+ rendered: /markdown_record/rendered/content/sandbox/sandbox_nested/bar_fragments.json
107
+ rendered: /markdown_record/rendered/content/sandbox/sandbox_nested/bar.json
104
108
  rendered: /markdown_record/rendered/content/sandbox/foo_fragments.json
105
109
  rendered: /markdown_record/rendered/content/sandbox/foo.json
106
- rendered: /markdown_record/rendered/content/configuration_fragments.json
107
- rendered: /markdown_record/rendered/content/configuration.json
108
- rendered: /markdown_record/rendered/content/controller_helpers_fragments.json
109
- rendered: /markdown_record/rendered/content/controller_helpers.json
110
+ rendered: /markdown_record/rendered/content/content_frags_fragments.json
111
+ rendered: /markdown_record/rendered/content/content_frags.json
112
+ rendered: /markdown_record/rendered/content/content_dsl_fragments.json
113
+ rendered: /markdown_record/rendered/content/content_dsl.json
114
+ rendered: /markdown_record/rendered/content/routes_fragments.json
115
+ rendered: /markdown_record/rendered/content/routes.json
116
+ rendered: /markdown_record/rendered/content/model_basics_fragments.json
117
+ rendered: /markdown_record/rendered/content/model_basics.json
118
+ rendered: /markdown_record/rendered/content/installation_fragments.json
119
+ rendered: /markdown_record/rendered/content/installation.json
120
+ rendered: /markdown_record/rendered/content/custom_models_and_associations_fragments.json
121
+ rendered: /markdown_record/rendered/content/custom_models_and_associations.json
110
122
  rendered: /markdown_record/rendered/content.html
111
- rendered: /markdown_record/rendered/content/custom_models_and_associations.html
112
- rendered: /markdown_record/rendered/content/erb_syntax_and_view_helpers.html
113
- rendered: /markdown_record/rendered/content/content_frags.html
114
- rendered: /markdown_record/rendered/content/model_basics.html
115
- rendered: /markdown_record/rendered/content/routes.html
116
- rendered: /markdown_record/rendered/content/content_dsl.html
117
123
  rendered: /markdown_record/rendered/content/rendering_basics.html
118
- rendered: /markdown_record/rendered/content/installation.html
119
124
  rendered: /markdown_record/rendered/content/home.html
125
+ rendered: /markdown_record/rendered/content/controller_helpers.html
126
+ rendered: /markdown_record/rendered/content/erb_syntax_and_view_helpers.html
127
+ rendered: /markdown_record/rendered/content/layouts.html
128
+ rendered: /markdown_record/rendered/content/configuration.html
120
129
  rendered: /markdown_record/rendered/content/sandbox.html
130
+ rendered: /markdown_record/rendered/content/sandbox/sandbox_nested.html
131
+ rendered: /markdown_record/rendered/content/sandbox/sandbox_nested/bar.html
121
132
  rendered: /markdown_record/rendered/content/sandbox/foo.html
122
- rendered: /markdown_record/rendered/content/configuration.html
123
- rendered: /markdown_record/rendered/content/controller_helpers.html
133
+ rendered: /markdown_record/rendered/content/content_frags.html
134
+ rendered: /markdown_record/rendered/content/content_dsl.html
135
+ rendered: /markdown_record/rendered/content/routes.html
136
+ rendered: /markdown_record/rendered/content/model_basics.html
137
+ rendered: /markdown_record/rendered/content/installation.html
138
+ rendered: /markdown_record/rendered/content/custom_models_and_associations.html
124
139
  ---------------------------------------------------------------
125
- 42 files rendered.
126
- 42 files saved.
140
+ 51 files rendered.
141
+ 51 files saved.
127
142
  ```
128
143
 
129
144
  Congratulations! You have installed MarkdownRecord. If you are not viewing this from the host application already, go ahead and start your Rails server and navigate to your <%= link_to("local host demo", "http://localhost:3000/mdr/content/home") %> to continue following this guide.
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "name": "Rendering Basics", "parent_id": "content/home" } -->
2
- <!--model { "type": "markdown_record/demo/section", "id": 2, "name": "Rendering Basics" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "name": "Rendering Basics", "relative_parent_id": "home" } -->
2
+ <!--model { "type": "section", "id": 2, "name": "Rendering Basics" } -->
3
3
 
4
4
  # Rendering Basics
5
5
 
@@ -25,7 +25,7 @@ In addition, MarkdownRecord also renders and extra JSON file with the `_fragment
25
25
 
26
26
  You will notice that each file and directory for this demo in the `content` directory has a numeric prefix. These prefixes are how MarkdownRecord determines the order of content in the concatenated files. By using a numeric prefix, the exact order can be specified leading to predictable results.
27
27
 
28
- By default, MarkdownRecord ignores these numeric prefixes for all other purposes. This means that they should not be included in id values for content fragments or in the `content_path` parameter when loading rendered content in the browser (more on both these topics will be discussed later in this guide.). Because of this, it is important that the portion of each filename that comes after the numeric prefix be unique within a subdirectory. If two filename only differ in their numeric prefix, there will be a conflict.
28
+ By default, MarkdownRecord ignores these numeric prefixes for all other purposes. This means that they should not be included in id values for content fragments or in the `content_path` parameter when loading rendered content in the browser (more on both these topics will be discussed later in this guide.). Because of this, it is important that the portion of each filename that comes after the numeric prefix be unique within a subdirectory. If two filename only differ in their numeric prefix, there will be a conflict. MarkdownRecord can use different kind of prefixes, including semantic versions and dates. More on this is discussed in the section on configuration.
29
29
 
30
30
  MarkdownRecord can render content using three different strategies: `file`, `directory` and `full`. The default strategy is `full` and will render all files and directories. The `file` strategy will render only files and will not concatenate source content for each directory. The `directory` strategy will only render the concatenated files for each directory.
31
31
 
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "parent_id": "content/home", "name": "Content DSL" } -->
2
- <!--model { "type": "markdown_record/demo/section", "id": 3, "name": "Content DSL" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "relative_parent_id": "home", "name": "Content DSL" } -->
2
+ <!--model { "type": "section", "id": 3, "name": "Content DSL" } -->
3
3
 
4
4
  # Content DSL
5
5
 
@@ -12,7 +12,7 @@ To do this, simply write an HTML comment like this in your markdown files:
12
12
  ```html
13
13
  <!---model
14
14
  {
15
- "type": "markdown_record/demo/dsl_command",
15
+ "type": "dsl_command",
16
16
  "id": 1,
17
17
  "name": "model",
18
18
  "example_id": 1
@@ -26,7 +26,7 @@ As you can see, all that is required is a JSON object inside a special comment t
26
26
 
27
27
  There are several different DSL commands that you can use to define application data within your markdown source documents. They are as follows:
28
28
 
29
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 1, "name": "model", "section_id": 3 } -->
29
+ <!--model { "type": "dsl_command", "id": 1, "name": "model", "section_id": 3 } -->
30
30
  <!--attribute:description:string-->
31
31
  - `model` is the main command that tells MarkdownRecord that you want to define a model or JSON object. The only attribute required in the json object you provide is the `type` attribute, which is used as an index in the final JSON output (each index points to an array of objects of that type). The type can be whatever you want if you don't plan on using corresponding Ruby models. If you *do* plan to use corresponding Ruby models, then the `type` attribute should match the fully qualified class name of the model in underscore form (i.e. `Foo::BarBaz` would be `foo/bar_baz`).
32
32
 
@@ -36,7 +36,7 @@ There are several different DSL commands that you can use to define application
36
36
  See the example above.
37
37
  <!--end_model-->
38
38
 
39
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 2, "name": "attribute", "section_id": 3 } -->
39
+ <!--model { "type": "dsl_command", "id": 2, "name": "attribute", "section_id": 3 } -->
40
40
  <!--attribute:description:string-->
41
41
  - `attribute:<attribute_name>:<type>` tells MarkdownRecord that any text that follows should be assigned to the top model on the stack as the value of the given attribute, until it sees the `end_attribute` command.
42
42
 
@@ -49,7 +49,7 @@ There are several different DSL commands that you can use to define application
49
49
  <!---attribute:description:string-->
50
50
  ```
51
51
  <!--end_model-->
52
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 3, "name": "end_attribute", "section_id": 3 } -->
52
+ <!--model { "type": "dsl_command", "id": 3, "name": "end_attribute", "section_id": 3 } -->
53
53
  <!--attribute:description:string-->
54
54
  - `end_attribute` tells MarkdownRecord to stop assigning text as an attribute value to the top model on the stack. If the top most model is popped before this command is given or the end of the source file is reached, then it implicitly stops assigning text to it.
55
55
  <!--end_attribute-->
@@ -60,7 +60,7 @@ There are several different DSL commands that you can use to define application
60
60
  <!---end_attribute-->
61
61
  ```
62
62
  <!--end_model-->
63
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 4, "name": "end_model", "section_id": 3 } -->
63
+ <!--model { "type": "dsl_command", "id": 4, "name": "end_model", "section_id": 3 } -->
64
64
  <!--attribute:description:string-->
65
65
  - `end_model` tells MarkdownRecord to pop the top model of the stack. This command isn't necessary unless you are defining models in a way that requires you to assign attributes to a model that is no longer the top model on the stack.
66
66
  <!--end_attribute-->
@@ -71,7 +71,7 @@ There are several different DSL commands that you can use to define application
71
71
  <!---end_model-->
72
72
  ```
73
73
  <!--end_model-->
74
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 5, "name": "fragment", "section_id": 3 } -->
74
+ <!--model { "type": "dsl_command", "id": 5, "name": "fragment", "section_id": 3 } -->
75
75
  <!--attribute:description:string-->
76
76
  - `fragment` is similar to `model` in that it expects a JSON object, but the object is assigned to the `meta` attribute of the `ContentFragment` corresponding to the current markdown file. As such, this command should only be used once in each file. This command provides a way of attaching custom data to ContentFragments, such as a layout you want to use for rendering from a controller, details about the content's author, or perhaps who should be able to access it, etc. You can then interact this data in your application code.
77
77
 
@@ -84,12 +84,12 @@ There are several different DSL commands that you can use to define application
84
84
  <!---fragment { "author": "Bryant Morrill" } -->
85
85
  ```
86
86
  <!--end_model-->
87
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 6, "name": "directory_fragment", "section_id": 3 } -->
87
+ <!--model { "type": "dsl_command", "id": 6, "name": "directory_fragment", "section_id": 3 } -->
88
88
  <!--attribute:description:string-->
89
89
  - `directory_fragment` is used exactly the same way as `fragment` but defines the `meta` attribute of the `ContentFragment` for the current directory. As such, this should only be used once per directory level, otherwise subsequently defined data might overwrite preceding data.
90
90
  <!--end_attribute-->
91
91
  <!--end_model-->
92
- <!--model { "type": "markdown_record/demo/dsl_command", "id": 7, "name": "use_layout", "section_id": 3 } -->
92
+ <!--model { "type": "dsl_command", "id": 7, "name": "use_layout", "section_id": 3 } -->
93
93
  <!--attribute:description:string-->
94
94
  - `use_layout:<path>` simply specifies a layout by its relative file path to use when rendering the current markdown file to HTML. This is useful for when you have specific markdown files that you want to render using a different layout than the layout configured for use with all other files.
95
95
  <!--end_attribute-->
@@ -97,7 +97,18 @@ There are several different DSL commands that you can use to define application
97
97
  Example:
98
98
 
99
99
  ```html
100
- <!--use_layout:_custom_layout.html.erb-->
100
+ <!---use_layout:_custom_layout.html.erb-->
101
+ ```
102
+ <!--end_model-->
103
+
104
+ - `scope:<scope_name>` defines a scope that will apply to all models defined in the current subdirectory and all nested directories until another scope is defines. By default, all models exist in the `nil` scope if no scope is defined. Scopes provide isolation for models, which allows you to copy content and reuse model ids, as long as the duplicate ids do not exist in the same scope. The trade off, however, is that you will need to provide the scope when querying for those models in your application code.
105
+
106
+ This is advantageous for things like versioned documents, where you want to duplicate your content and it would be a hassle to change ids and keep track of ids across versions.
107
+
108
+ Example:
109
+
110
+ ```html
111
+ <!---scope:v_0_1_4-->
101
112
  ```
102
113
  <!--end_model-->
103
114
 
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "parent_id": "content/home", "name": "Routes" } -->
2
- <!--model { "type": "markdown_record/demo/section", "id": 4, "name": "Routes" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "relative_parent_id": "home", "name": "Routes" } -->
2
+ <!--model { "type": "section", "id": 4, "name": "Routes" } -->
3
3
 
4
4
  # Routes
5
5
 
@@ -28,16 +28,19 @@ The download routes are not enabled by default, but can be enabled if you want t
28
28
 
29
29
  Here is a complete list of links to all the rendered HTML files of this demo (each item has a JSON and an HTML version), all of which use the routes described above:
30
30
 
31
- <% ::MarkdownRecord::ContentFragment.all.each do |frag| %>
31
+ - <%= link_to_markdown_record(fragment.parent, fragment.parent.id) %><br>
32
+ <% fragment.parent.children.each do |frag| %>
32
33
  - <%= link_to_markdown_record(frag, frag.id) %><br>
33
34
  <% end %>
34
35
 
35
- <% ::MarkdownRecord::ContentFragment.all.each do |frag| %>
36
- - <%= link_to_markdown_record_html(frag, frag.html_route) %><br>
36
+ - <%= link_to_markdown_record(fragment.parent, fragment.parent.id) %><br>
37
+ <% fragment.parent.children.each do |frag| %>
38
+ - <%= link_to_markdown_record_html(frag, frag.id) %><br>
37
39
  <% end %>
38
40
 
39
- <% ::MarkdownRecord::ContentFragment.all.each do |frag| %>
40
- - <%= link_to_markdown_record_json(frag, frag.json_route) %><br>
41
+ - <%= link_to_markdown_record(fragment.parent, fragment.parent.id) %><br>
42
+ <% fragment.parent.children.each do |frag| %>
43
+ - <%= link_to_markdown_record_json(frag, frag.id) %><br>
41
44
  <% end %>
42
45
 
43
46
  Some of the above routes are the rendered versions of individual files, and some are the concatenated and rendered contents of an entire directory.
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "parent_id": "content/home", "name": "Model Basics" } -->
2
- <!--model { "type": "markdown_record/demo/section", "id": 5, "name": "Model Basics" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "relative_parent_id": "home", "name": "Model Basics" } -->
2
+ <!--model { "type": "section", "id": 5, "name": "Model Basics" } -->
3
3
 
4
4
  # MarkdownRecord Models
5
5
 
@@ -27,18 +27,18 @@ The `type` attribute is the fully qualified class name of the model in underscor
27
27
  These methods all work similarly to ActiveRecord by design. For example, if we use the models defined in the previously in this guide, then we could do this:
28
28
 
29
29
  ```ruby
30
- ::MarkdownRecord::Demo::DslCommand.find(4)
31
- => #<MarkdownRecord::Demo::DslCommand description: "end_model tells MarkdownRecord to pop the top model of the stack. This command isn't necessary unless you are defining models in a way that requires you to assign attributes to a model that is no longer the top model on the stack.", filename: "content_dsl", id: 4, name: "end_model", subdirectory: "content/api_docs", type: "markdown_record/demo/dsl_command">
30
+ DslCommand.find(4)
31
+ => #<DslCommand description: "end_model tells MarkdownRecord to pop the top model of the stack. This command isn't necessary unless you are defining models in a way that requires you to assign attributes to a model that is no longer the top model on the stack.", filename: "content_dsl", id: 4, name: "end_model", subdirectory: "content/api_docs", type: "dsl_command">
32
32
 
33
33
  ```
34
34
 
35
35
  *or*
36
36
 
37
37
  ```ruby
38
- ::MarkdownRecord::Demo::DslCommand.all
38
+ DslCommand.all
39
39
  =>
40
- [#<MarkdownRecord::Demo::DslCommand description: "...", name: "model", ...>,
41
- #<MarkdownRecord::Demo::DslCommand description: "...", name: "attribute", ...>
40
+ [#<DslCommand description: "...", name: "model", ...>,
41
+ #<DslCommand description: "...", name: "attribute", ...>
42
42
  ...
43
43
  ]
44
44
  ```
@@ -73,18 +73,18 @@ Examples:
73
73
 
74
74
  ```ruby
75
75
  # querying with a string value
76
- MarkdownRecord::Demo::DslCommand.where(:name => "model").all
77
- => [#<MarkdownRecord::Demo::DslCommand ...>]
76
+ DslCommand.where(:name => "model").all
77
+ => [#<DslCommand ...>]
78
78
  ```
79
79
 
80
80
  ```ruby
81
81
  # querying for models that don't have "fragment" in the name.
82
- MarkdownRecord::Demo::DslCommand.where(__not__: { :name => /fragment/}).map(&:name)
82
+ DslCommand.where(__not__: { :name => /fragment/}).map(&:name)
83
83
  => ["model", "attribute", "end_attribute", "end_model", "use_layout"]
84
84
  ```
85
85
 
86
86
  ```ruby
87
- MarkdownRecord::Demo::DslCommand.where(__or__: [{ :name => /fragment/}, {:name => :null}]).map(&:name)
87
+ DslCommand.where(__or__: [{ :name => /fragment/}, {:name => :null}]).map(&:name)
88
88
  => ["model", "fragment", "directory_fragment"]
89
89
  ```
90
90
 
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "parent_id": "content/home", "name": "Content Fragments" } -->
2
- <!---model { "type": "markdown_record/demo/section", "id": 6, "name": "Content Fragments" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "relative_parent_id": "home", "name": "Content Fragments" } -->
2
+ <!--model { "type": "section", "id": 6, "name": "Content Fragments" } -->
3
3
 
4
4
  # Content Fragments
5
5
 
@@ -32,7 +32,7 @@ Each of the above associations use the file tree structure, meaning that they wi
32
32
 
33
33
  The `parent` method, however, can have its behavior overridden by setting a `parent_id` field in the `meta` hash of the content fragment to the id of another content fragment using the Content DSL.
34
34
 
35
- For example, the file that this text is written in is at `content/blog/content_frags.md`, meaning that the parent of the directory level content fragment with `id = "content/blog"` would normally be the directory level content fragment with `id = "content"`.
35
+ For example, the file that this text is written in is at `content/7_content_frags.md`, meaning that the parent of the directory level content fragment with `id = "content/content_frags"` would normally be the directory level content fragment with `id = "content"`.
36
36
 
37
37
  In code, this would look like:
38
38
 
@@ -41,10 +41,10 @@ MarkdownRecord::ContentFragment.find("content/content_frags").parent
41
41
  => #<MarkdownRecord::ContentFragment concatenated: true, filename: "content", id: "content", meta: {"name"=>"Demo", ...}, subdirectory: "", type: "markdown_record/content_fragment">
42
42
  ```
43
43
 
44
- But one of the files in in `content/blog` uses the Content DSL to define meta data for the directory content fragment, like so:
44
+ But this file uses the Content DSL to define meta data for the content fragment corresponding to it, like so:
45
45
 
46
46
  ```html
47
- <!---directory_fragment { "name": "Example: Blog", "parent_id": "content/home" } -->
47
+ <!---directory_fragment { "name": "Content Fragments", "parent_id": "content/home" } -->
48
48
  ```
49
49
 
50
50
  The `parent_id` in the `meta` hash overrides the default behavior, which changes what fragment is returned from `parent`:
@@ -65,6 +65,8 @@ MarkdownRecord::ContentFragment.find("content/sandbox/foo")
65
65
  => ["content/home", "content/sandbox"]
66
66
  ```
67
67
 
68
+ As an alternative to `parent_id`, you can use `relative_parent_id` which does the same thing, but accepts an id that is relative to the current file's containing directory. For example, the previous exampel would use `home` instead of `content/home` to assign the same fragment as the parent if the current file was in `content`.
69
+
68
70
  ## Instance Methods
69
71
 
70
72
  `MarkdownRecord::ContentFragment` has the following instance methods:
@@ -75,4 +77,5 @@ MarkdownRecord::ContentFragment.find("content/sandbox/foo")
75
77
  - `read_json`: reads the corresponding JSON file.
76
78
  - `read_html`: reads the corresponding HTML file.
77
79
  - `json_path`: returns the path to the corresponding JSON file.
78
- - `html_path`: returns the path to the corresponding HTML file.
80
+ - `html_path`: returns the path to the corresponding HTML file.
81
+ - `find_relative`: does the same thing as `MarkdownRecord::ContentFragment.find`, but is an instance method and finds another content fragment based on a retative path/id provided.
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "parent_id": "content/home", "name": "ERB Syntax and View Helpers" } -->
2
- <!---model { "type": "markdown_record/demo/section", "id": 7, "name": "ERB Syntax and View Helpers" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "relative_parent_id": "home", "name": "ERB Syntax and View Helpers" } -->
2
+ <!--model { "type": "section", "id": 7, "name": "ERB Syntax and View Helpers" } -->
3
3
 
4
4
  # ERB Syntax and View Helpers
5
5
 
@@ -13,6 +13,7 @@ MarkdownRecord supports the use of ERB syntax in your markdown source files. It
13
13
  - `subdirectory`: the subdirectory of the file being rendered.
14
14
  - `frag_id`: the id of the fragment corresponding to the file being rendered.
15
15
  - `fragment`: the content fragment model instance corresponding to the file being rendered.
16
+ - `scope`: the scope the file falls under, if any.
16
17
 
17
18
  ## Rails View Helpers
18
19
 
@@ -22,10 +23,30 @@ For example, the image below is rendered using the `image_tag` tag helper:
22
23
 
23
24
  <%= image_tag("ruby-logo") %>
24
25
 
26
+ MarkdownRecord models can also be passed to `dom_id` for use in Turbo-frames, etc:
27
+
28
+ ```
29
+ <%%= dom_id(fragment) %>
30
+ ```
31
+
25
32
  ## View Helpers
26
33
 
27
34
  MarkdownRecord provides the following view helpers to use in your ERB views as well as in your markdown content source files:
28
35
 
36
+ - `render_fragment`: renders the html content of the passed in contend fragment, or the fragment corresponding to the file where a MarkdownRecor model is defined.
37
+
38
+ For example:
39
+
40
+ ```
41
+ <%%= render_fragment(@post) %>
42
+ ```
43
+
44
+ Or
45
+
46
+ ```
47
+ <%%= render_fragment(@post.fragment) %>
48
+ ```
49
+
29
50
  - `link_to_markdown_record`: generates a link to the content fragment you pass in, or else the content fragment corresponding to the MarkdownRecord model you pass in.
30
51
 
31
52
  For example, for a content fragment such as:
@@ -38,7 +59,7 @@ MarkdownRecord provides the following view helpers to use in your ERB views as w
38
59
  When you pass it into the view helper like so:
39
60
 
40
61
  ```html
41
- <%%%= link_to_markdown_record(fragment)%>
62
+ <%%= link_to_markdown_record(fragment) %>
42
63
  ```
43
64
 
44
65
  The result would be the following markup:
@@ -49,16 +70,16 @@ MarkdownRecord provides the following view helpers to use in your ERB views as w
49
70
 
50
71
  Notice how the text in the link is the name value found in the content fragment meta attribute. This is because MarkdownRecord checks to see if the model passed in responds to `name`, and `MarkdownRecord::ContentFragment` has a `name` method that returns the `name` field, if present, from its meta hash.
51
72
 
52
- A fragment without a name will be rendered like this:
73
+ A fragment without a name will be rendered using the corresponding file name like this:
53
74
 
54
75
  ```html
55
- <a href="/mdr/content/erb_syntax_and_view_helpers">/mdr/content/blog/view_helpers</a>
76
+ <a href="/mdr/content/erb_syntax_and_view_helpers">view_helpers</a>
56
77
  ```
57
78
 
58
79
  Unless you pass in a name explicitly:
59
80
 
60
81
  ```html
61
- <%%%= link_to_markdown_record(fragment, "Click Here!") %>
82
+ <%%= link_to_markdown_record(fragment, "Click Here!") %>
62
83
  ```
63
84
 
64
85
  Which will produce:
@@ -79,10 +100,10 @@ MarkdownRecord provides the following view helpers to use in your ERB views as w
79
100
  Using the view helpers in conjunction with content fragments, you can easily build navigation that automatically updates when you rerender your content. This guide uses this technique and you can find the following code in the `_global_layout.html.erb` layout:
80
101
 
81
102
  ```html
82
- <%%% fragment.parents_from("content/home").each_with_index do |frag, index| %>
83
- <%%% unless index == 0%>
103
+ <%% fragment.parents_from("content/home").each_with_index do |frag, index| %>
104
+ <%% unless index == 0%>
84
105
  <span class="breadcrumb_divider">/</span>
85
- <%%% end %>
86
- <li><%%%= link_to_markdown_record(frag)%>
87
- <%%% end %>
106
+ <%% end %>
107
+ <li><%%= link_to_markdown_record(frag) %>
108
+ <%% end %>
88
109
  ```
@@ -1,5 +1,5 @@
1
- <!--fragment { "author": "Bryant Morrill", "parent_id": "content/home", "name": "Layouts" } -->
2
- <!---model { "type": "markdown_record/demo/section", "id": 8, "name": "Layouts" } -->
1
+ <!--fragment { "author": "Bryant Morrill", "relative_parent_id": "home", "name": "Layouts" } -->
2
+ <!--model { "type": "section", "id": 8, "name": "Layouts" } -->
3
3
 
4
4
  # Layouts
5
5
 
@@ -11,5 +11,5 @@ The layouts that MarkdownRecord uses by default are added to your application at
11
11
  - `_concatenated_layout.html.erb`: this is the layout used only for concatenated files. It will only be rendered once per file, but not for files that don't contain the concatenated contents of a directory. Some of the pages of this guide have a blue border, which is a style defined only in this layout.
12
12
  - `_global_layout.html.erb`: this is the layout that is used for every rendered file, regardless of whether it is a concatenated file or not. This is the recommended layout to use for global styles, etc.
13
13
 
14
- In addition to the above, there is also a `_custom_layout.html.erb` which is used for the contents of the <%= link_to_markdown_record(::MarkdownRecord::ContentFragment.find("content/sandbox"), "sandbox") %> part of this guide. This demonstrates how you can override the layout used for a specific file using the `user_layout` Content DSL command.
14
+ In addition to the above, there is also a `_custom_layout.html.erb` which is used for the contents of the <%= link_to_markdown_record(fragment.find_relative("sandbox"), "sandbox") %> part of this guide. This demonstrates how you can override the layout used for a specific file using the `user_layout` Content DSL command.
15
15
 
@@ -82,6 +82,7 @@
82
82
 
83
83
  <div class="container">
84
84
  <div class="navigation">
85
+ <div>Version: <%= MarkdownRecord::VERSION %></div>
85
86
  <ul>
86
87
  <li>Breadcrumbs: </li>
87
88
  <% fragment.parents_from("content/home").each_with_index do |frag, index| %>