Add backend for tips and enable markdown support
This commit is contained in:
@@ -13,11 +13,11 @@
|
||||
.card-body.p-3
|
||||
h5
|
||||
= t('exercises.implement.tips.description')
|
||||
= tip.description
|
||||
= render_markdown(tip.description)
|
||||
- if tip.example?
|
||||
h5.mt-2
|
||||
h5
|
||||
= t('exercises.implement.tips.example')
|
||||
pre
|
||||
code.mh-100 class="language-#{tip.file_type.editor_mode.gsub("ace/mode/", "")}"
|
||||
code.mh-100 class="language-#{tip.file_type.programming_language}"
|
||||
= tip.example
|
||||
= render(partial: 'tips/collapsed_card', collection: exercise_tip.children, as: :exercise_tip)
|
||||
|
21
app/views/tips/_form.html.slim
Normal file
21
app/views/tips/_form.html.slim
Normal file
@@ -0,0 +1,21 @@
|
||||
= form_for(@tip, builder: PagedownFormBuilder) do |f|
|
||||
= render('shared/form_errors', object: @tip)
|
||||
.form-group
|
||||
= f.label(:title)
|
||||
= f.text_field(:title, class: 'form-control', required: false)
|
||||
.form-group
|
||||
= f.label(:description)
|
||||
= f.pagedown :description, input_html: { preview: true, rows: 5 }
|
||||
.form-group
|
||||
= f.label(:file_type_id, t('activerecord.attributes.file.file_type_id'))
|
||||
= f.collection_select(:file_type_id, @file_types, :id, :name, {include_blank: true}, class: 'form-control')
|
||||
.form-group
|
||||
= f.label(:example)
|
||||
= f.text_area(:example, class: 'code-field form-control', rows: 5, style: "display:none;", required: false)
|
||||
#editor-edit.original-input data-file-id=@tip.id
|
||||
#frames
|
||||
.edit-frame
|
||||
.editor-content.d-none
|
||||
.editor.allow_ace_tooltip
|
||||
.actions = render('shared/submit_button', f: f, object: @tip)
|
||||
.editor
|
3
app/views/tips/edit.html.slim
Normal file
3
app/views/tips/edit.html.slim
Normal file
@@ -0,0 +1,3 @@
|
||||
h1 = @tip.to_s
|
||||
|
||||
= render('form')
|
20
app/views/tips/index.html.slim
Normal file
20
app/views/tips/index.html.slim
Normal file
@@ -0,0 +1,20 @@
|
||||
h1 = Tip.model_name.human(count: 2)
|
||||
|
||||
.table-responsive
|
||||
table.sortable.table
|
||||
thead
|
||||
tr
|
||||
th = t('activerecord.attributes.tip.title')
|
||||
th = t('activerecord.attributes.file.file_type')
|
||||
th colspan=3 = t('shared.actions')
|
||||
tbody
|
||||
- @tips.each do |tip|
|
||||
tr
|
||||
td = link_to_if(policy(tip).show?, tip.title || tip.to_s, tip)
|
||||
td = tip.file_type ? link_to_if(policy(tip.file_type).show?, tip.file_type.name, tip.file_type) : ''
|
||||
td = link_to(t('shared.show'), tip) if policy(tip).show?
|
||||
td = link_to(t('shared.edit'), edit_tip_path(tip)) if policy(tip).edit?
|
||||
td = link_to(t('shared.destroy'), tip, data: {confirm: t('shared.confirm_destroy')}, method: :delete) if tip.can_be_destroyed? && policy(tip).destroy?
|
||||
|
||||
= render('shared/pagination', collection: @tips)
|
||||
p = render('shared/new_button', model: Tip, path: new_tip_path)
|
3
app/views/tips/new.html.slim
Normal file
3
app/views/tips/new.html.slim
Normal file
@@ -0,0 +1,3 @@
|
||||
h1 = t('shared.new_model', model: Tip.model_name.human)
|
||||
|
||||
= render('form')
|
17
app/views/tips/show.html.slim
Normal file
17
app/views/tips/show.html.slim
Normal file
@@ -0,0 +1,17 @@
|
||||
- content_for :head do
|
||||
// Force a full page reload, see https://github.com/turbolinks/turbolinks/issues/326.
|
||||
Otherwise, code might not be highlighted correctly (race condition)
|
||||
meta name='turbolinks-visit-control' content='reload'
|
||||
= javascript_pack_tag('highlight', 'data-turbolinks-track': true)
|
||||
= stylesheet_pack_tag('highlight', media: 'all', 'data-turbolinks-track': true)
|
||||
|
||||
h1
|
||||
= @tip.to_s
|
||||
= render('shared/edit_button', object: @tip)
|
||||
|
||||
= row(label: 'tip.title', value: @tip.title)
|
||||
= row(label: 'tip.description', value: render_markdown(@tip.description), class: 'm-0')
|
||||
= row(label: 'file.file_type', value: @tip.file_type_id? ? \
|
||||
link_to_if(policy(@tip.file_type).show?, @tip.file_type.name, @tip.file_type) : '')
|
||||
= row(label: 'tip.example', value: @tip.file_type_id? ? \
|
||||
code_tag(@tip.example, @tip.file_type.programming_language) : '')
|
Reference in New Issue
Block a user