Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Changes made to enables I18n of workflows on generated grafs #35

Closed
wants to merge 1 commit into from

2 participants

@jfelipesp

Changes made to enables localization os the workflows, based on the I18n
gem. i've also included a sample structure(via comments) on how the
localization file should be constructed.

@jfelipesp jfelipesp Changes made to enables localization os the workflows, based on the I18n
gem.  i've also included a sample structure(via comments) on how the
localization file should be constructed.
d12f20a
@geekq
Owner

Hi jfelipesp,

you implementation looks nice. Are sure it works with Rails 2.2?
I still have to maintain some older projects so have to ensure the backward compatibility.

Best Regards,

geekQ

@jfelipesp

Hi geekQ, i'll check it out and provide a feedback.

@geekq
Owner

Closing for now (due inactivity). Please reopen if you have new input.

@geekq geekq closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 9, 2011
  1. @jfelipesp

    Changes made to enables localization os the workflows, based on the I18n

    jfelipesp authored
    gem.  i've also included a sample structure(via comments) on how the
    localization file should be constructed.
This page is out of date. Refresh to see the latest.
Showing with 42 additions and 30 deletions.
  1. +42 −30 lib/workflow.rb
View
72 lib/workflow.rb
@@ -363,38 +363,50 @@ def self.included(klass)
# @param klass A class with the Workflow mixin, for which you wish the graphical workflow representation
# @param [String] target_dir Directory, where to save the dot and the pdf files
# @param [String] graph_options You can change graph orientation, size etc. See graphviz documentation
- def self.create_workflow_diagram(klass, target_dir='.', graph_options='rankdir="LR", size="7,11.6", ratio="fill"')
- workflow_name = "#{klass.name.tableize}_workflow".gsub('/', '_')
- fname = File.join(target_dir, "generated_#{workflow_name}")
- File.open("#{fname}.dot", 'w') do |file|
- file.puts %Q|
-digraph #{workflow_name} {
- graph [#{graph_options}];
- node [shape=box];
- edge [len=1];
- |
-
- klass.workflow_spec.states.each do |state_name, state|
- file.puts %Q{ #{state.name} [label="#{state.name}"];}
- state.events.each do |event_name, event|
- meta_info = event.meta
- if meta_info[:doc_weight]
- weight_prop = ", weight=#{meta_info[:doc_weight]}"
- else
- weight_prop = ''
+ #
+ # ====================================
+ # I18n file structure based on state names and event names per workflow
+ # "pt-BR":
+ # workflow:
+ # workflow_name:
+ # states:
+ # state_1: Begin
+ # state_2: Review Information
+ # state_3: End
+ # events:
+ # state_1:
+ # event_1: assign
+ # state_2:
+ # event_1: revised
+ # ====================================
+ def self.create_workflow_diagram(klass, target_dir='.', graph_options='rankdir="LR", size="5,3", ratio="fill"')
+ workflow_name = "#{klass.name.tableize}_workflow".gsub('/', '_')
+ fname = File.join(target_dir, "generated_#{workflow_name}")
+ File.open("#{fname}.dot", 'w') do |file|
+ file.puts %Q|
+ digraph #{workflow_name} {
+ graph [#{graph_options}];
+ node [shape=box];
+ edge [len=1];
+ |
+
+ klass.workflow_spec.states.each do |state_name, state|
+ file.puts %Q{#{state.name} [label="#{I18n.t("workflow.#{klass.name.downcase}.states.#{state_name}")}"];}
+
+ state.events.each do |event_name, event|
+ meta_info = event.meta
+ if meta_info[:doc_weight]
+ weight_prop = ", weight=#{meta_info[:doc_weight]}"
+ else
+ weight_prop = ''
+ end
+ file.puts %Q{ #{state.name} -> #{event.transitions_to} [label="#{I18n.t("workflow.#{klass.name.downcase}.events.#{state_name}.#{event_name}")}" #{weight_prop}];}
end
- file.puts %Q{ #{state.name} -> #{event.transitions_to} [label="#{event_name.to_s.humanize}" #{weight_prop}];}
end
+ file.puts "}"
+ file.puts
end
- file.puts "}"
- file.puts
+ `dot -Tpdf -o'#{fname}.pdf' '#{fname}.dot'`
+ puts "Please run the following to open the generated file: open '#{fname}.pdf'"
end
- `dot -Tpdf -o'#{fname}.pdf' '#{fname}.dot'`
- puts "
-Please run the following to open the generated file:
-
-open '#{fname}.pdf'
-
-"
- end
end
Something went wrong with that request. Please try again.