Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[v#.#.#] ([month] [YYYY])
- Liquid: evaluate Liquid content before rendering all issues/evidence tables
- Wizard: add analytics sharing step
- [entity]:
- [future tense verb] [feature]
- Upgraded gems:
- [gem]
- Bugs fixes:
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/markup_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ def editor_paths
source_url: main_app.source_fields_path
}
end

def liquified_field(field, record)
LiquidParser.new(
field: field,
project: current_project,
record: record
).parse
end
end
39 changes: 39 additions & 0 deletions app/services/liquid_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class LiquidParser
attr_accessor :field, :project, :record

def initialize(field: nil, project:, record:)
@field = field
@project = project
@record = record
end

def parse
@output ||= HTML::Pipeline::Dradis::LiquidFilter.call(
value,
liquid_assigns: liquid_assigns
).strip
end

private

def value
if field
record.fields[field]
else
record.content
end
end

def liquid_assigns
project_assigns = LiquidCachedAssigns.new(project: project)

project_assigns.merge(record_assigns)
end

def record_assigns
record_class = record.class.to_s
drop_class = "#{record_class}Drop".constantize

{ record_class.underscore => drop_class.new(record) }
end
end
3 changes: 2 additions & 1 deletion app/views/issues/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
when 'Updated'
[issue.updated_at.to_i, local_time_ago(issue.updated_at)]
else
[issue.fields.fetch(column, ''), markup(issue.fields.fetch(column, ''))]
text = liquified_field(column, issue)
[text, markup(text)]
end
%>
<%= content_tag :td,
Expand Down
3 changes: 2 additions & 1 deletion app/views/issues/evidence/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
when 'Updated'
[evidence.updated_at.to_i, local_time_ago(evidence.updated_at)]
else
[evidence.fields.fetch(column, ''), markup(evidence.fields.fetch(column, ''))]
text = liquified_field(column, evidence)
[text, markup(text)]
end
%>
<td data-sort="<%= sort %>"><%= display %></td>
Expand Down
3 changes: 2 additions & 1 deletion app/views/nodes/items_table/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
when 'Updated'
[item.updated_at.to_i, local_time_ago(item.updated_at)]
else
[item.fields.fetch(column, ''), markup(item.fields.fetch(column, ''))]
text = liquified_field(column, item)
[text, markup(text)]
end
%>
<td data-sort="<%= sort %>"><%= display %></td>
Expand Down
Loading