<commit_before>
class MetadataPlugin < Noosfero::Plugin

  def self.plugin_name
    I18n.t 'metadata_plugin.lib.plugin.name'
  end

  def self.plugin_description
    I18n.t 'metadata_plugin.lib.plugin.description'
  end

  def self.config
    @config ||= HashWithIndifferentAccess.new(YAML.load File.read("#{File.dirname __FILE__}/../config.yml")) rescue {}
  end

  def self.og_types
    @og_types ||= self.config[:open_graph][:types]
  end

  def head_ending
    plugin = self
    lambda do
      options = MetadataPlugin::Spec::Controllers[controller.controller_path.to_sym]
      options ||= MetadataPlugin::Spec::Controllers[:profile] if controller.is_a? ProfileController
      options ||= MetadataPlugin::Spec::Controllers[:environment]
      return unless options

      return unless object = case variable = options[:variable]
        when Proc then instance_exec(&variable) rescue nil
        else instance_variable_get variable
        end
      return unless metadata = (object.class.const_get(:Metadata) rescue nil)

      metadata.map do |property, contents|
        contents = contents.call(object, plugin) rescue nil if contents.is_a? Proc
        next if contents.blank?

        Array(contents).map do |content|
          content = content.call(object, plugin) rescue nil if content.is_a? Proc
          next if content.blank?
          tag 'meta', property: property, content: CGI.escape_html(content)
        end.join
      end.join
    end
  end

  # context HELPERS
  def og_url_for options
    options.delete :port
    options[:host] = self.class.config[:open_graph][:domain]
    Noosfero::Application.routes.url_helpers.url_for options
  end

  protected

end

ActiveSupport.run_load_hooks :metadata_plugin, MetadataPlugin
<commit_msg>metadata: Convert to string<commit_after>
class MetadataPlugin < Noosfero::Plugin

  def self.plugin_name
    I18n.t 'metadata_plugin.lib.plugin.name'
  end

  def self.plugin_description
    I18n.t 'metadata_plugin.lib.plugin.description'
  end

  def self.config
    @config ||= HashWithIndifferentAccess.new(YAML.load File.read("#{File.dirname __FILE__}/../config.yml")) rescue {}
  end

  def self.og_types
    @og_types ||= self.config[:open_graph][:types]
  end

  def head_ending
    plugin = self
    lambda do
      options = MetadataPlugin::Spec::Controllers[controller.controller_path.to_sym]
      options ||= MetadataPlugin::Spec::Controllers[:profile] if controller.is_a? ProfileController
      options ||= MetadataPlugin::Spec::Controllers[:environment]
      return unless options

      return unless object = case variable = options[:variable]
        when Proc then instance_exec(&variable) rescue nil
        else instance_variable_get variable
        end
      return unless metadata = (object.class.const_get(:Metadata) rescue nil)

      metadata.map do |property, contents|
        contents = contents.call(object, plugin) rescue nil if contents.is_a? Proc
        next if contents.blank?

        Array(contents).map do |content|
          content = content.call(object, plugin) rescue nil if content.is_a? Proc
          next if content.blank?
          tag 'meta', property: property, content: CGI.escape_html(content.to_s)
        end.join
      end.join
    end
  end

  # context HELPERS
  def og_url_for options
    options.delete :port
    options[:host] = self.class.config[:open_graph][:domain]
    Noosfero::Application.routes.url_helpers.url_for options
  end

  protected

end

ActiveSupport.run_load_hooks :metadata_plugin, MetadataPlugin

{'fraction_non_alphanumeric': 0.0943769426391636, 'fraction_numerical': 0.0022605255721955355, 'mean_word_length': 3.430538172715895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3002546', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1030, 'n_words': 249}