<commit_before>module Netzke
  module ActionViewExt
    # Include JavaScript
    def netzke_js_include
      # ExtJS
      res = ENV['RAILS_ENV'] == 'development' ? javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all-debug.js") : javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all.js")
      # Netzke (dynamically generated)
      res << javascript_include_tag("/netzke/netzke.js")
    end

    # Include CSS
    def netzke_css_include(theme_name = :default)
      # ExtJS base
      res = stylesheet_link_tag("/extjs/resources/css/ext-all.css")
      # ExtJS theming
      res << stylesheet_link_tag("/extjs/resources/css/xtheme-#{theme_name}.css") unless theme_name == :default
      # Netzke (dynamically generated)
      res << stylesheet_link_tag("/netzke/netzke.css")
      res
    end
    
    # JavaScript for all Netzke classes in this view, and Ext.onReady which renders all Netzke widgets in this view
    def netzke_js
      javascript_tag <<-END_OF_JAVASCRIPT
        Netzke.authenticityToken = '#{form_authenticity_token}'
        #{@content_for_netzke_js_classes}
        Ext.onReady(function(){
          #{@content_for_netzke_on_ready}
        });
      END_OF_JAVASCRIPT
    end
    
    # Wrapper for all the above. Use it in your layout.
    # Params: <tt>:ext_theme</tt> - the name of ExtJS theme to apply (optional)
    # E.g.:
    #   <%= netzke_init :ext_theme => "grey" %>
    def netzke_init(params = {})
      theme = params[:ext_theme] || :default
      [netzke_css_include(theme), netzke_js_include, netzke_js].join("\n")
    end
    
    # Use this helper in your views to embed Netzke widgets. E.g.:
    #   netzke :my_grid, :widget_class_name => "GridPanel", :columns => [:id, :name, :created_at]
    # On how to configure a widget, see documentation for Netzke::Base or/and specific widget
    def netzke(name, config = {})
      class_name = config[:widget_class_name] ||= name.to_s.classify
      config[:name] = name
      Netzke::Base.reg_widget(config)
      w = Netzke::Base.instance_by_config(config)
      content_for :netzke_js_classes, w.js_missing_code(@rendered_classes ||= [])
      content_for :netzke_on_ready, w.js_widget_instance
      content_for :netzke_on_ready, w.js_widget_render
      
      # Now mark this widget's class as rendered, so that we only generate it once per view
      @rendered_classes << class_name unless @rendered_classes.include?(class_name)

      # Return the html for this widget
      w.js_widget_html
    end
  end
end
<commit_msg>better widget class name guessing<commit_after>module Netzke
  module ActionViewExt
    # Include JavaScript
    def netzke_js_include
      # ExtJS
      res = ENV['RAILS_ENV'] == 'development' ? javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all-debug.js") : javascript_include_tag("/extjs/adapter/ext/ext-base.js", "/extjs/ext-all.js")
      # Netzke (dynamically generated)
      res << javascript_include_tag("/netzke/netzke.js")
    end

    # Include CSS
    def netzke_css_include(theme_name = :default)
      # ExtJS base
      res = stylesheet_link_tag("/extjs/resources/css/ext-all.css")
      # ExtJS theming
      res << stylesheet_link_tag("/extjs/resources/css/xtheme-#{theme_name}.css") unless theme_name == :default
      # Netzke (dynamically generated)
      res << stylesheet_link_tag("/netzke/netzke.css")
      res
    end
    
    # JavaScript for all Netzke classes in this view, and Ext.onReady which renders all Netzke widgets in this view
    def netzke_js
      javascript_tag <<-END_OF_JAVASCRIPT
        Netzke.authenticityToken = '#{form_authenticity_token}'
        #{@content_for_netzke_js_classes}
        Ext.onReady(function(){
          #{@content_for_netzke_on_ready}
        });
      END_OF_JAVASCRIPT
    end
    
    # Wrapper for all the above. Use it in your layout.
    # Params: <tt>:ext_theme</tt> - the name of ExtJS theme to apply (optional)
    # E.g.:
    #   <%= netzke_init :ext_theme => "grey" %>
    def netzke_init(params = {})
      theme = params[:ext_theme] || :default
      [netzke_css_include(theme), netzke_js_include, netzke_js].join("\n")
    end
    
    # Use this helper in your views to embed Netzke widgets. E.g.:
    #   netzke :my_grid, :widget_class_name => "GridPanel", :columns => [:id, :name, :created_at]
    # On how to configure a widget, see documentation for Netzke::Base or/and specific widget
    def netzke(name, config = {})
      class_name = config[:widget_class_name] ||= name.to_s.camelcase
      config[:name] = name
      Netzke::Base.reg_widget(config)
      w = Netzke::Base.instance_by_config(config)
      content_for :netzke_js_classes, w.js_missing_code(@rendered_classes ||= [])
      content_for :netzke_on_ready, w.js_widget_instance
      content_for :netzke_on_ready, w.js_widget_render
      
      # Now mark this widget's class as rendered, so that we only generate it once per view
      @rendered_classes << class_name unless @rendered_classes.include?(class_name)

      # Return the html for this widget
      w.js_widget_html
    end
  end
end

{'fraction_non_alphanumeric': 0.10992009354901579, 'fraction_numerical': 0.0, 'mean_word_length': 3.182559087204564, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3490851', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1721, 'n_words': 382}