Class: Cucumber::Parser::I18n::Language
- Defined in:
- lib/cucumber/parser/i18n/language.rb
Constant Summary collapse
- KEYWORD_KEYS =
%w{name native encoding feature background scenario scenario_outline examples given when then but}
- LANGUAGES =
Hash.new{|h,k| h[k] = Language.new(k)}
Class Method Summary collapse
- .[](key) ⇒ Object
-
.alias_step_definitions(keywords) ⇒ Object
:nodoc:.
-
.alias_steps(keywords) ⇒ Object
Sets up additional method aliases for Given, When and Then.
- .inspect ⇒ Object
Instance Method Summary collapse
- #and_keywords ⇒ Object
- #but_keywords ⇒ Object
- #incomplete? ⇒ Boolean
-
#initialize(lang) ⇒ Language
constructor
A new instance of Language.
- #keywords(key, raw = false) ⇒ Object
- #parse(source, path, filter) ⇒ Object
- #parser ⇒ Object
- #scenario_keyword ⇒ Object
Constructor Details
#initialize(lang) ⇒ Language
Returns a new instance of Language.
35 36 37 38 39 |
# File 'lib/cucumber/parser/i18n/language.rb', line 35 def initialize(lang) @keywords = Cucumber::LANGUAGES[lang] raise "Language not supported: #{lang.inspect}" if @keywords.nil? @keywords['grammar_name'] = @keywords['name'].gsub(/\s/, '') end |
Class Method Details
.[](key) ⇒ Object
10 11 12 |
# File 'lib/cucumber/parser/i18n/language.rb', line 10 def [](key) LANGUAGES[key] end |
.alias_step_definitions(keywords) ⇒ Object
:nodoc:
14 15 16 17 |
# File 'lib/cucumber/parser/i18n/language.rb', line 14 def alias_step_definitions(keywords) #:nodoc: all_keywords = %w{given when then and but}.map{|keyword| keywords[keyword].split('|')}.flatten alias_steps(all_keywords) end |
.alias_steps(keywords) ⇒ Object
Sets up additional method aliases for Given, When and Then. This does not affect how feature files are parsed. If you want to create aliases in the parser, you have to do this in languages.yml. For example:
and: And|With
25 26 27 28 29 30 |
# File 'lib/cucumber/parser/i18n/language.rb', line 25 def alias_steps(keywords) keywords.each do |adverb| StepMother.alias_adverb(adverb) World.alias_adverb(adverb) end end |
.inspect ⇒ Object
50 51 52 |
# File 'lib/cucumber/parser/i18n/language.rb', line 50 def @parser.inspect "#<#{self.class.name}>" end |
Instance Method Details
#and_keywords ⇒ Object
81 82 83 |
# File 'lib/cucumber/parser/i18n/language.rb', line 81 def and_keywords @keywords['and'].split('|') end |
#but_keywords ⇒ Object
77 78 79 |
# File 'lib/cucumber/parser/i18n/language.rb', line 77 def but_keywords @keywords['but'].split('|') end |
#incomplete? ⇒ Boolean
69 70 71 |
# File 'lib/cucumber/parser/i18n/language.rb', line 69 def incomplete? KEYWORD_KEYS.detect{|key| @keywords[key].nil?} end |
#keywords(key, raw = false) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/cucumber/parser/i18n/language.rb', line 62 def keywords(key, raw=false) return @keywords[key] if raw return nil unless @keywords[key] values = @keywords[key].split('|') values.map{|value| "'#{value}'"}.join(" / ") end |
#parse(source, path, filter) ⇒ Object
56 57 58 59 60 |
# File 'lib/cucumber/parser/i18n/language.rb', line 56 def parse(source, path, filter) feature = parser.parse_or_fail(source, path, filter) feature.language = self if feature feature end |
#parser ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cucumber/parser/i18n/language.rb', line 41 def parser return @parser if @parser i18n_tt = File.(File.dirname(__FILE__) + '/../i18n.tt') template = File.open(i18n_tt, Cucumber.file_mode('r')).read erb = ERB.new(template) grammar = erb.result(binding) Treetop.load_from_string(grammar) self.class.alias_step_definitions(@keywords) @parser = Parser::I18n.const_get("#{@keywords['grammar_name']}Parser").new def @parser.inspect "#<#{self.class.name}>" end @parser end |
#scenario_keyword ⇒ Object
73 74 75 |
# File 'lib/cucumber/parser/i18n/language.rb', line 73 def scenario_keyword @keywords['scenario'].split('|')[0] + ':' end |