-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.html
More file actions
311 lines (309 loc) Β· 18.9 KB
/
README.html
File metadata and controls
311 lines (309 loc) Β· 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Jinda README Preview</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.min.css" />
</head>
<body>
<header id="title-block-header">
<h1 class="title">Jinda README Preview</h1>
</header>
<h1
id="jinda-gem---quick-start-guide-building-a-notes-articles-or-documents-app">Jinda
Gem - Quick Start Guide: Building a Notes, Articles, or Documents
App</h1>
<p>Jinda generates complete Rails applications from a Freemind mindmap
file (<code>app/jinda/index.mm</code>). All generated code (models,
controllers, views, etc.) originates from templates in the Jinda gem at
<code>$HOME/mygem/jinda/lib/generators/jinda/templates/app</code>.
During <code>rails generate jinda:install</code> and
<code>rake jinda:update</code>, these templates are copied and populated
based on your mindmap. Code between <code># jinda begin</code> and
<code># jinda end</code> in generated files is overwritten on updates;
add custom code outside these markers to preserve it.</p>
<p>This guide focuses on using the default mindmap to manage Notes,
Articles, or Documents. The default <code>index.mm</code> (generated
from the gem template) includes ready-to-use branches for these. Edit
<code>app/jinda/index.mm</code> in Freemind, save, then run
<code>rake jinda:update</code> to regenerate code.</p>
<figure>
<img src="doc/images/map_index.png" alt="Default Mindmap" />
<figcaption aria-hidden="true">Default Mindmap</figcaption>
</figure>
<p>The mindmap has three main branches: - <strong>models</strong>:
Defines MongoDB models (via Mongoid). - <strong>services</strong>:
Defines left-side menu modules (main menu) and services (sub-menu
workflows). - <strong>roles</strong>: Defines user roles (e.g., admin,
member). Defaults suffice; leave intact unless customizing.</p>
<h2 id="models-defining-your-data-structure">Models: Defining Your Data
Structure</h2>
<p>The default <strong>models</strong> branch includes samples like
<code>person</code>, <code>address</code>, <code>article</code>,
<code>note</code>, <code>picture</code>, and <code>comment</code>. For a
Notes app, use/modify <code>note</code>; for Articles, use
<code>article</code>; for Documents, adapt <code>picture</code> or add
<code>document</code>.</p>
<p>Under a model (singular, Rails convention), sub-branches define
fields: - Plain text (e.g., <code>title</code>): Default String field. -
With type (e.g., <code>body: text</code>): Mongoid type (string,
integer, date, boolean, array, etc.). - Raw code (e.g.,
<code>belongs_to :user</code>): Right-click branch > Insert > Icon
> pen (edit icon) to add Mongoid associations, validations, indexes,
etc. - File uploads (e.g., <code>file</code>): Use String; Jinda handles
storage (filesystem/Cloudinary) and URL generation.</p>
<p>Example: Default <code>note</code> model (for Notes app):</p>
<pre><code>models
βββ note
βββ include Mongoid::Attributes::Dynamic (pen icon: enables dynamic fields)
βββ title (String)
βββ body (text)
βββ belongs_to :user (pen icon: association)
βββ before_validation :ensure_title_has_a_value (pen icon: callback)
βββ validates :title, length: { maximum: 30 }, presence: true (pen icon: validation)
βββ private def ensure_title_has_a_value ... end (pen icon: method)</code></pre>
<figure>
<img src="doc/images/models_note.png" alt="models-note" />
<figcaption aria-hidden="true">models-note</figcaption>
</figure>
<p>Save and run <code>rake jinda:update</code>. This updates
<code>app/models/note.rb</code> (generated from gem template
<code>lib/generators/jinda/templates/app/models/note.rb</code>):</p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode ruby"><code class="sourceCode ruby"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># jinda begin</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="cf">class</span> <span class="dt">Note</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">include</span> <span class="dt">Mongoid</span><span class="kw">::</span><span class="dt">Document</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">include</span> <span class="dt">Mongoid</span><span class="kw">::</span><span class="dt">Attributes</span><span class="kw">::</span><span class="dt">Dynamic</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> field <span class="wa">:title</span>, <span class="wa">type: </span><span class="dt">String</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> field <span class="wa">:body</span>, <span class="wa">type: </span><span class="dt">String</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> belongs_to <span class="wa">:user</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a> before_validation <span class="wa">:ensure_title_has_a_value</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a> validates <span class="wa">:title</span>, <span class="wa">presence: </span><span class="dv">true</span>, <span class="wa">length: </span><span class="kw">{</span> <span class="wa">maximum: </span><span class="dv">30</span> <span class="kw">}</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a> <span class="co"># ... private method ...</span></span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="co"># jinda end</span></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a><span class="cf">end</span></span></code></pre></div>
<p>For Articles (<code>article</code> model): Fields like
<code>title</code>, <code>text</code>, <code>body</code>, with
<code>belongs_to :user</code> and <code>has_many :comments</code>.</p>
<p>For Documents: Modify <code>picture</code> (fields:
<code>picture</code>, <code>description</code>,
<code>belongs_to :user</code>) or add <code>document</code> with
<code>title</code>, <code>file: string</code>,
<code>belongs_to :user</code>.</p>
<p>Add custom code (e.g., scopes) outside markers.</p>
<h2 id="services-building-menus-and-workflows">Services: Building Menus
and Workflows</h2>
<p>Defaults include <code>users</code>, <code>admins</code>,
<code>devs</code> (leave intact for auth/admin). Ready services:
<code>notes: Notes</code> (for Notes), <code>articles: Article</code>
(for Articles), <code>docs: Document</code> (for Documents).</p>
<p>Each module (first sub-branch, e.g., <code>notes: Notes</code>)
creates: - Controller (<code>app/controllers/notes_controller.rb</code>,
from template). - Main menu item (βNotesβ).</p>
<p>Sub-branches define access/steps: - <code>role: m</code>: Restricts
to βmβ (member role). - <code>link:label:/path</code>: Simple link
(e.g., <code>link:My Notes:/notes/my</code> β submenu linking to user
notes). - Service branches: Multi-step workflows. - Screen icon (UI):
View form (e.g., <code>new_note: New</code> β
<code>app/views/notes/new/new_note.html.erb</code>, from template). -
Sub-branch rules: e.g., <code>role: m</code> or
<code>rule: login? && own_note?</code>. - Bookmark icon:
Controller method (e.g., <code>create</code> β <code>def create</code>).
- Forward icon: Redirect (e.g., to <code>/notes/my</code>).</p>
<p>Example: Default <code>notes: Notes</code> service (for
creating/editing notes):</p>
<pre><code>services
βββ notes: Notes (module: menu "Notes")
βββ link:My Notes:/notes/my (role: m)
βββ new: New Note (service)
βββ new_note: New (screen icon, role: m)
βββ create: Create (bookmark icon)
βββ /notes/my (forward icon: redirect)
βββ edit: Edit (service)
βββ select_note: Select (screen, role: m)
βββ edit_note: Edit (screen, role: m)
βββ update: Update (bookmark)
βββ delete: Delete (service, fork style)
βββ select_note: Select (screen, role: m)
βββ delete: Delete (bookmark)
βββ ... (mail, xedit)</code></pre>
<figure>
<img src="doc/images/services_notes.png" alt="services-notes" />
<figcaption aria-hidden="true">services-notes</figcaption>
</figure>
<p>Example: Add an βarticlesβ module (default
<code>articles: Article</code> service, for creating/editing articles
with comments):</p>
<pre><code>services
βββ articles: Article (module: menu "Articles")
βββ link:All Articles:/articles
βββ link:My article:/articles/my (role: m)
βββ new_article: New Article (service)
βββ form_article: New Article (screen icon, role: m)
βββ create: Create Article (bookmark icon)
βββ /articles/my (forward icon: redirect)
βββ edit_article: Edit Article (service)
βββ select_article: Select Article (screen, role: m)
βββ edit_article: Edit Article (screen, role: m)
βββ j_update: Update Article (bookmark)
βββ xedit_article: xEdit Article (hidden service)
βββ edit_article: Edit Article (screen, role: m)
βββ j_update: Update Article (bookmark)
βββ comments: Comment (service, linked to articles)
βββ new_comment: New Comment (role: m)
β βββ create (bookmark)
βββ /articles/my (forward icon: redirect)</code></pre>
<figure>
<img src="doc/images/services_articles.png" alt="services-articles" />
<figcaption aria-hidden="true">services-articles</figcaption>
</figure>
<p>Save and run <code>rake jinda:update</code>. Generates/updates: -
<code>app/controllers/notes_controller.rb</code> (skeleton from
template; add custom logic outside markers). - Views like
<code>app/views/notes/new/new_note.html.erb</code> (basic form from
template; uncomment/edit fields):</p>
<pre class="erb"><code><!-- app/views/notes/new/new_note.html.erb -->
<h1>New Note</h1>
<%= f.text_field :title, placeholder: "Note Title" %>
<%= f.text_area :body, placeholder: "Note Body", rows: 10 %>
<!-- Jinda provides form_tag, submit --></code></pre>
<p>In controller, implement methods (e.g., <code>create</code> outside
markers):</p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode ruby"><code class="sourceCode ruby"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="co"># app/controllers/notes_controller.rb</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="cf">class</span> <span class="dt">NotesController</span> <span class="kw"><</span> <span class="dt">ApplicationController</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="co"># jinda begin</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># ... generated skeleton ...</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># jinda end</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">def</span> create</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> <span class="ot">@note</span> <span class="kw">=</span> <span class="dt">Note</span><span class="at">.new</span>(note_params)</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a> <span class="ot">@note</span><span class="at">.user</span> <span class="kw">=</span> current_user</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> <span class="ot">@note</span><span class="at">.save</span></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a> redirect_to notes_my_path, <span class="wa">notice: </span><span class="st">"Note created!"</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a> render <span class="wa">:new_note</span></span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a> <span class="at">private</span></span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a> <span class="cf">def</span> note_params</span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a> params<span class="at">.require</span>(<span class="wa">:note</span>)<span class="at">.permit</span>(<span class="wa">:title</span>, <span class="wa">:body</span>)</span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a><span class="cf">end</span></span></code></pre></div>
<p>Similar for <code>articles: Article</code> (create/edit with
comments) and <code>docs: Document</code> (new/edit with file
upload).</p>
<p>For full CRUD: Defaults include list (<code>/notes/my</code>), edit,
delete. Add steps like <code>show_note: Show</code> (screen icon) for
views.</p>
<p>Test: <code>rails s</code>, login (admin/secret), navigate to βNotesβ
> βnewβ.</p>
<h2 id="roles-user-permissions">Roles: User Permissions</h2>
<p>Defaults: <code>m: member</code> (basic), <code>a: admin</code>
(full), <code>d: developer</code>. Reference in services (e.g.,
<code>role: m</code>). Add roles like <code>editor: Editor</code> if
needed.</p>
<h2 id="next-steps">Next Steps</h2>
<ul>
<li>Seed: <code>rails jinda:seed</code>.</li>
<li>MongoDB: <code>docker run -d -p 27017:27017 mongo</code>.</li>
<li>Customize: Edit mindmap (e.g., add fields to <code>note</code>), run
<code>rake jinda:update</code>.</li>
<li>Themes:
<code>gem 'jinda_adminlte'; bundle install; rails g jinda_adminlte:install</code>.</li>
<li>API: Defaults include <code>api/v1/notes</code> for RESTful
endpoints.</li>
<li>Advanced: Multi-step rules, polymorphic comments (already in
<code>comment</code> model).</li>
</ul>
<p>Iterate: Modify mindmap, update, test login/menu at
<code>localhost:3000</code>. For new apps, extend defaults for your
Notes/Articles/Documents workflow.</p>
</body>
</html>