diff options
Diffstat (limited to 'guides/rails_guides')
-rw-r--r-- | guides/rails_guides/generator.rb | 37 | ||||
-rw-r--r-- | guides/rails_guides/markdown.rb | 8 |
2 files changed, 31 insertions, 14 deletions
diff --git a/guides/rails_guides/generator.rb b/guides/rails_guides/generator.rb index c83538ad48..7d4a15962c 100644 --- a/guides/rails_guides/generator.rb +++ b/guides/rails_guides/generator.rb @@ -17,13 +17,14 @@ module RailsGuides class Generator GUIDES_RE = /\.(?:erb|md)\z/ - def initialize(edge:, version:, all:, only:, kindle:, language:) - @edge = edge - @version = version - @all = all - @only = only - @kindle = kindle - @language = language + def initialize(edge:, version:, all:, only:, kindle:, language:, direction: "ltr") + @edge = edge + @version = version + @all = all + @only = only + @kindle = kindle + @language = language + @direction = direction if @kindle check_for_kindlegen @@ -62,9 +63,9 @@ module RailsGuides end def mobi - mobi = "ruby_on_rails_guides_#{@version || @edge[0, 7]}" - mobi += ".#{@language}" if @language - mobi += ".mobi" + mobi = +"ruby_on_rails_guides_#{@version || @edge[0, 7]}" + mobi << ".#{@language}" if @language + mobi << ".mobi" end def initialize_dirs @@ -116,6 +117,14 @@ module RailsGuides def copy_assets FileUtils.cp_r(Dir.glob("#{@guides_dir}/assets/*"), @output_dir) + + if @direction == "rtl" + overwrite_css_with_right_to_left_direction + end + end + + def overwrite_css_with_right_to_left_direction + FileUtils.mv("#{@output_dir}/stylesheets/main.rtl.css", "#{@output_dir}/stylesheets/main.css") end def output_file_for(guide) @@ -141,8 +150,8 @@ module RailsGuides puts "Generating #{guide} as #{output_file}" layout = @kindle ? "kindle/layout" : "layout" - view = ActionView::Base.new( - @source_dir, + view = ActionView::Base.with_empty_template_cache.with_view_paths( + [@source_dir], edge: @edge, version: @version, mobi: "kindle/#{mobi}", @@ -155,7 +164,7 @@ module RailsGuides # Generate the special pages like the home. # Passing a template handler in the template name is deprecated. So pass the file name without the extension. - result = view.render(layout: layout, formats: [$1], file: $`) + result = view.render(layout: layout, formats: [$1.to_sym], file: $`) else body = File.read("#{@source_dir}/#{guide}") result = RailsGuides::Markdown.new( @@ -198,7 +207,7 @@ module RailsGuides def check_fragment_identifiers(html, anchors) html.scan(/<a\s+href="#([^"]+)/).flatten.each do |fragment_identifier| next if fragment_identifier == "mainCol" # in layout, jumps to some DIV - unless anchors.member?(fragment_identifier) + unless anchors.member?(CGI.unescape(fragment_identifier)) guess = anchors.min { |a, b| Levenshtein.distance(fragment_identifier, a) <=> Levenshtein.distance(fragment_identifier, b) } diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index a98aa8fe66..018f49ffd0 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -3,6 +3,7 @@ require "redcarpet" require "nokogiri" require "rails_guides/markdown/renderer" +require "rails-html-sanitizer" module RailsGuides class Markdown @@ -20,6 +21,7 @@ module RailsGuides @raw_body = body extract_raw_header_and_body generate_header + generate_description generate_title generate_body generate_structure @@ -82,6 +84,11 @@ module RailsGuides @header = engine.render(@raw_header).html_safe end + def generate_description + sanitizer = Rails::Html::FullSanitizer.new + @description = sanitizer.sanitize(@header).squish + end + def generate_structure @headings_for_index = [] if @body.present? @@ -165,6 +172,7 @@ module RailsGuides def render_page @view.content_for(:header_section) { @header } + @view.content_for(:description) { @description } @view.content_for(:page_title) { @title } @view.content_for(:index_section) { @index } @view.render(layout: @layout, html: @body.html_safe) |