Last active
August 29, 2015 14:05
-
-
Save rossmari/448228c09ecbc01829c9 to your computer and use it in GitHub Desktop.
epic_piece_of_shit.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% #Founded in old legacy project - epic crazy piece of BAD code %> | |
<div id="second_body"> | |
<% #TODO Переделать нижележащий кусок кода нахрен: %> | |
<%- content = capture do -%> | |
<%- if article.article_type != Article::ANNOUNCEMENT -%> | |
<%- right_articles = article.right_articles.actual.all(:conditions => "type != 'ArtDossier'") -%> | |
<% #NOTE Вот согласно этому куску - правые - на которых мы ссылаемся, а левые - которые на нас ссылаются. %> | |
<%- incut_size = article.incuts.size + (article.poll ? 1 : 0) + (right_articles.any? ? 1 : 0) -%> | |
<%- doc = Hpricot(formating_text(article.content)) -%> | |
<%- p_tags_raw = doc.search("/") -%> | |
<%- p_tags = p_tags_raw.inject([]) {|s, c| s << if c.inner_html !~ /\A\s*( )*\s*\z/ && !c.inner_html.nil? then c else nil end; }.compact -%> | |
<%- ratio = incut_size.zero? ? 0 : p_tags.size.to_f / incut_size -%> | |
<%- incut_nums = (0..incut_size).to_a.map {|x| (ratio * x).to_i} -%> | |
<%- incuts = article.incuts -%> | |
<%- incuts.unshift(article.poll) if article.poll -%> | |
<%- incuts = incuts + [right_articles] if right_articles.any? -%> | |
<div id="hypercontext"> | |
<index> | |
<%- p_tags.each_with_index do |p_tag, curr_p| -%> | |
<%= (!incut_size.zero? && incut_nums.include?(curr_p)) ? incut_text(incuts[incut_nums.index(curr_p)], article) : "" unless hide_incuts -%> | |
<%= p_tag.to_s -%> | |
<%- end -%> | |
</index> | |
</div> | |
<%- else -%> | |
<%= formating_text(article.content) -%> | |
<%- end -%> | |
<%- end -%> | |
<%- if (article.article_type == Article::NEWS && (article.is_our? || article.is_main?)) || article.article_type == Article::BLOG -%> | |
<%= content -%> | |
<%- else -%> | |
<%= @sape_context.replace_in_text_segment( content ) -%> | |
<%- end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment