Module: Kuroko2::JobDefinitionsHelper

Defined in:
app/helpers/kuroko2/job_definitions_helper.rb

Instance Method Summary collapse

Instance Method Details

#first_line(text) ⇒ Object



3
4
5
# File 'app/helpers/kuroko2/job_definitions_helper.rb', line 3

def first_line(text)
  truncate(text.split("\n").first, length: 140)
end

#format_kuroko_script(script_text) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/kuroko2/job_definitions_helper.rb', line 38

def format_kuroko_script(script_text)
  script_text.each_line.map { |line|
    matched = Kuroko2::Workflow::ScriptParser::LINE_REGEXP.match(line.chomp)
    case matched && matched[:type]
    when 'wait'
      format_wait_task(line, matched)
    when 'sub_process'
      format_sub_process_task(line, matched)
    else
      ERB::Util.html_escape(line)
    end
  }.join('').html_safe
end

#markdown_format(text) ⇒ Object



7
8
9
10
# File 'app/helpers/kuroko2/job_definitions_helper.rb', line 7

def markdown_format(text)
  pipeline = HTML::Pipeline.new([HTML::Pipeline::MarkdownFilter])
  raw(pipeline.call(text)[:output].to_s)
end


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/kuroko2/job_definitions_helper.rb', line 16

def star_link_for(definition)
  if stared_with(definition)
    link_to(
      raw('<i class="fa fa-star"></i>'),
      job_definition_star_path(id: stared_with(definition), job_definition_id: definition),
      remote: true,
      method: :delete,
      class: 'star',
      data: { definition_id: definition.id, star_id: stared_with(definition).id, definitions_path: job_definitions_path }
    )
  else
    link_to(
      raw('<i class="fa fa-star-o"></i>'),
      job_definition_stars_path(definition.id),
      remote: true,
      method: :post,
      class: 'star',
      data: { definition_id: definition.id, definitions_path: job_definitions_path }
    )
  end
end

#stared_with(definition) ⇒ Object



12
13
14
# File 'app/helpers/kuroko2/job_definitions_helper.rb', line 12

def stared_with(definition)
  current_user.stars.find {|star| star.job_definition_id == definition.id }
end