Skip to content

Commit

Permalink
Finished default layout formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Dec 29, 2010
1 parent 0e4bb13 commit fc9670f
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 68 deletions.
2 changes: 1 addition & 1 deletion examples/RailsGuides/config/kitabu.yml
Expand Up @@ -25,7 +25,7 @@ published_at: "2010-12-19"
subject: "These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together."

# Some keywords that identify this book.
keywords: "[Your book keywords (comma-separated)]"
keywords: "Ruby on Rails, Ruby, MVC, Getting Started, PDF, HOWTO, Web Development, Framework"

# Some unique identification. Works great with your domain
# like `http://yourbook.example.com`.
Expand Down
38 changes: 25 additions & 13 deletions examples/RailsGuides/output/RailsGuides.html
@@ -1,15 +1,16 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head>
<title>Rails Guides: Getting Started</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../templates/layout.css"/>
<link rel="stylesheet" type="text/css" href="../templates/syntax.css"/>
<link rel="stylesheet" type="text/css" href="../templates/user.css"/>

<meta name="author" content="Rails Documentation Team" />
<meta name="subject" content="These guides are designed to make you immediately productive with Rails, and to help you understand how all of the pieces fit together." />
<meta name="keywords" content="[Your book keywords (comma-separated)]" />
<meta name="keywords" content="Ruby on Rails, Ruby, MVC, Getting Started, PDF, HOWTO, Web Development, Framework" />
<meta name="date" content="2010-12-19" />
</head>
<body>
<div class="frontcover container">
Expand Down Expand Up @@ -532,7 +533,17 @@ <h3 id="using-the-console">Using the Console</h3>

<p>After the console loads, you can use it to work with your application&#x2019;s models:</p>

<p>["&lt;pre", "class=\"#{config[:theme]}\"&gt;#{code}"]</p>
<pre class="idle"><code>&gt;&gt; p = Post.new(:content =&gt; "A new post")
=&gt; #&lt;Post id: nil, name: nil, title: nil,
content: "A new post", created_at: nil,
updated_at: nil&gt;
&gt;&gt; p.save
=&gt; false
&gt;&gt; p.errors
=&gt; #&lt;OrderedHash { :title=&gt;["can't be blank",
"is too short (minimum is 5 characters)"],
:name=&gt;["can't be blank"] }&gt;</code></pre>


<p>This code shows creating a new <code>Post</code> instance, attempting to save it and getting <code>false</code> for a return value (indicating that the save failed), and inspecting the errors of the post.</p>

Expand Down Expand Up @@ -1263,18 +1274,19 @@ <h3 id="deleting-associated-objects">Deleting Associated Objects</h3>

<p>Rails provides a very simple HTTP authentication system that will work nicely in this situation. First, we enable simple HTTP based authentication in our <code>app/controllers/application_controller.rb</code>:</p>

<pre><code>class ApplicationController &lt; ActionController::Base
<pre class="idle"><span class="Keyword">class</span> <span class="TypeName">ApplicationController<span class="InheritedClass"> <span class="InheritedClass">&lt;</span> ActionController::Base</span></span>
&#xA0;&#xA0;protect_from_forgery

&#xA0;&#xA0;private
&#xA0;&#xA0;<span class="Keyword">private</span>

&#xA0;&#xA0;def authenticate
&#xA0;&#xA0;&#xA0;&#xA0;authenticate_or_request_with_http_basic do |user_name, password|
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;user_name == 'admin' &amp;&amp; password == 'password'
&#xA0;&#xA0;&#xA0;&#xA0;end
&#xA0;&#xA0;end
end
</code></pre>
&#xA0;&#xA0;&#xA0;&#xA0;authenticate_or_request_with_http_basic <span class="Keyword">do </span>|<span class="Variable">user_name</span>, <span class="Variable">password</span>|
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;user_name <span class="Keyword">==</span> <span class="String"><span class="String">'</span>admin<span class="String">'</span></span> <span class="Keyword">&amp;&amp;</span> password <span class="Keyword">==</span> <span class="String"><span class="String">'</span>password<span class="String">'</span></span>
&#xA0;&#xA0;&#xA0;&#xA0;<span class="Keyword">end</span>
&#xA0;&#xA0;<span class="Keyword">end</span>
<span class="Keyword">end</span>
</pre>


<p>You can obviously change the username and password to whatever you want. We put this method inside of <code>ApplicationController</code> so that it is available to all of our controllers.</p>

Expand Down
Binary file modified examples/RailsGuides/output/RailsGuides.pdf
Binary file not shown.
60 changes: 46 additions & 14 deletions examples/RailsGuides/templates/layout.css
@@ -1,7 +1,7 @@
/* ============ */
/* = DEFAULTS = */
/* ============ */
html {
html * {
font: normal normal normal 12pt/normal Constantia, Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, serif;
}

Expand All @@ -22,8 +22,9 @@ html {
@bottom-right {
color: #000;
content: counter(page);
font-family: helvetica, arial, sans-serif;
font-size: 12px;
margin-top: 0px;
margin-top: -10px;
margin-right: -40px;
}
}
Expand All @@ -47,13 +48,17 @@ html {
/* ============= */
/* = BOOKMARKS = */
/* ============= */
.imprint h2,
.chapter h4,
.chapter h5,
.chapter h6 {
h1, h2, h3, h4, h5, h6 {
prince-bookmark-level: none;
}

.frontcover h1 { prince-bookmark-level: 1; }
.chapter h2 { prince-bookmark-level: 2; }
.chapter h3 { prince-bookmark-level: 3; }
.chapter h4 { prince-bookmark-level: 4; }
.chapter h5 { prince-bookmark-level: 5; }
.chapter h6 { prince-bookmark-level: 6; }

/* ============= */
/* = CONTAINER = */
/* ============= */
Expand Down Expand Up @@ -124,15 +129,14 @@ div.frontcover * {

.chapter a {
color: #0AE;
font-weight: bold;
text-decoration: none;
}

.chapter h2,
.chapter h3,
.chapter h4,
.chapter h5 {
margin-top: 25pt;
margin: 25pt 0 15pt 0;
}

.chapter h2 {
Expand All @@ -143,28 +147,39 @@ div.frontcover * {
string-set: header "Chapter " counter(chapter) ": " content();
}

div.chapter h2::before {
.chapter h2::before {
content: "Chapter " counter(chapter);
color: #c0c0c0;
color: #999;
display: block;
font-size: 18pt;
letter-spacing: 0;
margin-bottom: .2em;
white-space: pre;
}

.chapter h3,
.chapter h5 {
font-family: "helvetica", arial, sans-serif;
}

.chapter h3 {
color: #888;
font-size: 24pt;
color: #b62f32;
font-size: 28px;
}

.chapter h4 {
font-size: 18pt;
font-size: 18px;
font-family: "helvetica neue", "arial narrow", sans-serif;
}

.chapter h5 {
font-size: 16pt;
font-size: 15px;
}

.chapter h6 {
font-size: 15px;
font-weight: normal;
text-transform: uppercase;
}

/* =========== */
Expand Down Expand Up @@ -201,6 +216,12 @@ pre, code {
font-size: 9pt;
}

pre, pre code {
font-size: 8pt;
line-height: 1.4;
padding-left: 25pt;
}

/* ========= */
/* = TABLE = */
/* ========= */
Expand Down Expand Up @@ -318,3 +339,14 @@ div.table-of-contents div.level6 {
acronym:after {
content: " (" attr(title) ")";
}

/* ============= */
/* = HIGHLIGHT = */
/* ============= */
.highlight {
font-size: 20pt;
}

.highlight strong {
color: #b62f32;
}
7 changes: 4 additions & 3 deletions examples/RailsGuides/templates/layout.erb
@@ -1,7 +1,7 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<head>
<title><%= title %></title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../templates/layout.css"/>
<link rel="stylesheet" type="text/css" href="../templates/syntax.css"/>
Expand All @@ -10,6 +10,7 @@
<meta name="author" content="<%= authors.join(', ') %>" />
<meta name="subject" content="<%= subject %>" />
<meta name="keywords" content="<%= keywords %>" />
<meta name="date" content="<%= published_at %>" />
</head>
<body>
<div class="frontcover container">
Expand Down
20 changes: 11 additions & 9 deletions examples/RailsGuides/text/09_Security.mkdn
Expand Up @@ -4,17 +4,19 @@ If you were to publish your blog online, anybody would be able to add, edit and

Rails provides a very simple HTTP authentication system that will work nicely in this situation. First, we enable simple HTTP based authentication in our `app/controllers/application_controller.rb`:

class ApplicationController < ActionController::Base
  protect_from_forgery
@@@ ruby
class ApplicationController < ActionController::Base
  protect_from_forgery

  private
  private

  def authenticate
    authenticate_or_request_with_http_basic do |user_name, password|
      user_name == 'admin' && password == 'password'
    end
  end
end
  def authenticate
    authenticate_or_request_with_http_basic do |user_name, password|
      user_name == 'admin' && password == 'password'
    end
  end
end
@@@

You can obviously change the username and password to whatever you want. We put this method inside of `ApplicationController` so that it is available to all of our controllers.

Expand Down
18 changes: 15 additions & 3 deletions lib/kitabu/cli.rb
@@ -1,4 +1,4 @@
# encoding: utf-8
# -*- encoding: utf-8 -*-
module Kitabu
class Cli < Thor
FORMATS = %w[pdf html epub]
Expand Down Expand Up @@ -26,7 +26,7 @@ def new(path)

desc "export [OPTIONS]", "Export e-book"
method_option :only, :type => :string, :desc => "Can be one of: #{FORMATS.join(", ")}"
method_option :auto, :type => :boolean, :desc => "Watch changes and automatically generate files"
method_option :auto, :type => :boolean, :desc => "Watch changes and automatically export files"

def export
if options[:only] && !FORMATS.include?(options[:only])
Expand All @@ -45,7 +45,7 @@ def version
say "Kitabu version #{Version::STRING}"
end

desc "permalinks", "List all title permalinks"
desc "permalinks", "List title permalinks"

def permalinks
html = Kitabu::Parser::Html.new(root_dir).content
Expand All @@ -65,6 +65,18 @@ def permalinks
end
end

desc "syntaxes", "List available syntaxes"

def syntaxes
say Uv.syntaxes.join(", ")
end

desc "themes", "List available themes"

def themes
say Uv.themes.join(", ")
end

private
def inside_ebook!
unless File.exist?(config_path)
Expand Down
3 changes: 2 additions & 1 deletion lib/kitabu/syntax.rb
Expand Up @@ -69,7 +69,8 @@ def process
end

if meta[:language] == "text"
code = %w[<pre class="#{config[:theme]}">#{code}</code>]
code.gsub!(/</, "&lt;")
code = %[<pre class="#{config[:theme]}"><code>#{code}</code></pre>]
else
silence_warnings do
code = Uv.parse(code, "xhtml", meta[:language], false, config[:theme])
Expand Down
2 changes: 1 addition & 1 deletion spec/kitabu/extensions/string_spec.rb
@@ -1,4 +1,4 @@
# encoding: utf-8
# -*- encoding: utf-8 -*-
require "spec_helper"

describe String do
Expand Down
2 changes: 1 addition & 1 deletion spec/kitabu/syntax_spec.rb
@@ -1,4 +1,4 @@
# encoding: utf-8
# -*- encoding: utf-8 -*-
require "spec_helper"

describe Kitabu::Syntax do
Expand Down
2 changes: 1 addition & 1 deletion spec/kitabu/toc_spec.rb
@@ -1,4 +1,4 @@
# encoding: utf-8
# -*- encoding: utf-8 -*-
require "spec_helper"

describe Kitabu::Toc do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/mybook/config/kitabu.yml
Expand Up @@ -43,7 +43,7 @@ authors:

# The theme that will be used for source
# code syntax highlighting.
theme: idle
theme: mac_classic

# The base URL from your source code.
base_url: http://example.com
Expand Down

0 comments on commit fc9670f

Please sign in to comment.