Class: Deplate::Command::ABBREV
- Inherits:
-
Deplate::Command
- Object
- Element
- Deplate::Command
- Deplate::Command::ABBREV
- Defined in:
- lib/deplate/commands.rb
Constant Summary collapse
- @@abbrevn =
0
Class Method Summary collapse
Methods inherited from Deplate::Command
commands, #finish, #format_special, #process, register_as, #setup, #setup_command, update_variables
Methods included from Names
name_match_c, name_match_fs, name_match_sf
Methods inherited from Element
#join_lines, #join_lines_re_zh_cn
Class Method Details
.accumulate(src, array, deplate, text, match, args, cmd) ⇒ Object
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
# File 'lib/deplate/commands.rb', line 782 def accumulate(src, array, deplate, text, match, args, cmd) Deplate::Core.log("%s: %s" % [cmd, text], :debug, src) rx = nil rs = nil tx = nil cmd = nil catch(:exit) do w = args['word'] || args['w'] || args['wd'] if w # rs = %{\\b%s\\b} % Regexp.escape(w) # rs = %{\\b%s(?=[^#{Deplate::HyperLink.chars}])} % Regexp.escape(w) rs = %{\\b%s(?=([[:punct:][:cntrl:][:space:]]|$))} % Regexp.escape(w) # tx = "#{Deplate::Core.remove_backslashes(text.inspect)}" # tx = "#{text.inspect}" # tx = text.inspect tx = text throw :exit end s = args['symbol'] || args['sym'] if s rs = %{`%s} % Regexp.escape(s) # tx = "#{Deplate::Core.remove_backslashes(text.inspect)}" # tx = text.inspect tx = text throw :exit end r = args['regexp'] || args['rx'] if r rs = r tx = lambda {|p| p.match[0].gsub(Regexp.new(r), text)} throw :exit end end if rs if args['plain'] # cmd = %{@deplate.formatter.plain_text(#{tx})} cmd = lambda {|c, t| c.deplate.formatter.plain_text(t)} specific = false elsif args['native'] or args['ins'] cmd = lambda {|c, t| t} specific = true else # cmd = %{@deplate.parse_and_format(@container, #{tx}, false)} cmd = lambda {|c, t| c.deplate.parse_and_format(c, t, false)} specific = false end deplate..abbrevs[[rs, deplate.formatter.formatter_name]] = [tx, cmd] rx = Regexp.new("^#{rs}") # body = <<-EOR # set_rx(#{rx.inspect}) # def setup # @elt = #{cmd} # end # EOR body = " set_rx(\#{rx.inspect})\n def setup\n tx, cmd = @deplate.options.abbrevs[[\#{rs.inspect}, @deplate.formatter.formatter_name]]\n case cmd\n when Proc\n tx = tx.call(self) if tx.kind_of?(Proc)\n @elt = cmd.call(@container, tx)\n when String\n @elt = cmd\n else\n log(['Internal error', 'ABBREV', \#{rs.inspect}, cmd.class], :error)\n end\n end\n EOR\n cls = Deplate::Cache.particle(deplate, body, \n :register => true,\n :specific => specific,\n :unshift => args['priority']\n )\n else\n Deplate::Core.log([\"No pattern specified\", args], :error, src)\n end\nend\n" |