amber 0.2.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -1
  3. data/README.md +88 -19
  4. data/bin/amber +26 -13
  5. data/lib/amber.rb +25 -39
  6. data/lib/amber/cli.rb +25 -1
  7. data/lib/amber/i18n.rb +43 -0
  8. data/lib/amber/render/apache.rb +44 -0
  9. data/lib/amber/render/asset.rb +28 -2
  10. data/lib/amber/render/helpers/blog_helper.rb +35 -0
  11. data/lib/amber/render/helpers/date_helper.rb +14 -0
  12. data/lib/amber/render/helpers/haml_helper.rb +9 -0
  13. data/lib/amber/render/helpers/html_helper.rb +30 -8
  14. data/lib/amber/render/helpers/navigation_helper.rb +31 -32
  15. data/lib/amber/render/layout.rb +2 -1
  16. data/lib/amber/render/template.rb +24 -11
  17. data/lib/amber/render/view.rb +31 -12
  18. data/lib/amber/server.rb +122 -56
  19. data/lib/amber/site.rb +171 -29
  20. data/lib/amber/site_configuration.rb +26 -11
  21. data/lib/amber/static_page.rb +34 -20
  22. data/lib/amber/static_page/filesystem.rb +3 -7
  23. data/lib/amber/static_page/page_properties.rb +7 -0
  24. data/lib/amber/static_page/render.rb +47 -31
  25. data/lib/amber/templates/apache_config.erb +12 -0
  26. data/lib/amber/templates/apache_config_with_prefix.erb +14 -0
  27. data/lib/amber/templates/htaccess.erb +176 -0
  28. data/lib/amber/version.rb +5 -0
  29. data/locales/rails-i18n/af.yml +201 -0
  30. data/locales/rails-i18n/ar.yml +274 -0
  31. data/locales/rails-i18n/az.yml +192 -0
  32. data/locales/rails-i18n/bg.yml +192 -0
  33. data/locales/rails-i18n/bn.yml +175 -0
  34. data/locales/rails-i18n/bs.yml +243 -0
  35. data/locales/rails-i18n/ca.yml +192 -0
  36. data/locales/rails-i18n/cs.yml +210 -0
  37. data/locales/rails-i18n/cy.yml +242 -0
  38. data/locales/rails-i18n/da.yml +198 -0
  39. data/locales/rails-i18n/de-AT.yml +202 -0
  40. data/locales/rails-i18n/de-CH.yml +206 -0
  41. data/locales/rails-i18n/de.yml +202 -0
  42. data/locales/rails-i18n/el.yml +198 -0
  43. data/locales/rails-i18n/en-AU.yml +198 -0
  44. data/locales/rails-i18n/en-CA.yml +207 -0
  45. data/locales/rails-i18n/en-GB.yml +198 -0
  46. data/locales/rails-i18n/en-IE.yml +198 -0
  47. data/locales/rails-i18n/en-IN.yml +198 -0
  48. data/locales/rails-i18n/en-NZ.yml +198 -0
  49. data/locales/rails-i18n/en-US.yml +204 -0
  50. data/locales/rails-i18n/en-ZA.yml +204 -0
  51. data/locales/rails-i18n/en.yml +204 -0
  52. data/locales/rails-i18n/eo.yml +194 -0
  53. data/locales/rails-i18n/es-419.yml +207 -0
  54. data/locales/rails-i18n/es-AR.yml +198 -0
  55. data/locales/rails-i18n/es-CL.yml +192 -0
  56. data/locales/rails-i18n/es-CO.yml +198 -0
  57. data/locales/rails-i18n/es-CR.yml +198 -0
  58. data/locales/rails-i18n/es-EC.yml +204 -0
  59. data/locales/rails-i18n/es-MX.yml +204 -0
  60. data/locales/rails-i18n/es-PA.yml +204 -0
  61. data/locales/rails-i18n/es-PE.yml +177 -0
  62. data/locales/rails-i18n/es-US.yml +198 -0
  63. data/locales/rails-i18n/es-VE.yml +198 -0
  64. data/locales/rails-i18n/es.yml +192 -0
  65. data/locales/rails-i18n/et.yml +192 -0
  66. data/locales/rails-i18n/eu.yml +192 -0
  67. data/locales/rails-i18n/fa.yml +192 -0
  68. data/locales/rails-i18n/fi.yml +192 -0
  69. data/locales/rails-i18n/fr-CA.yml +200 -0
  70. data/locales/rails-i18n/fr-CH.yml +200 -0
  71. data/locales/rails-i18n/fr.yml +214 -0
  72. data/locales/rails-i18n/gl.yml +171 -0
  73. data/locales/rails-i18n/he.yml +194 -0
  74. data/locales/rails-i18n/hi-IN.yml +192 -0
  75. data/locales/rails-i18n/hi.yml +192 -0
  76. data/locales/rails-i18n/hr.yml +236 -0
  77. data/locales/rails-i18n/hu.yml +192 -0
  78. data/locales/rails-i18n/id.yml +193 -0
  79. data/locales/rails-i18n/is.yml +212 -0
  80. data/locales/rails-i18n/iso-639-2/csb.yml +203 -0
  81. data/locales/rails-i18n/iso-639-2/dsb.yml +208 -0
  82. data/locales/rails-i18n/iso-639-2/fur.yml +192 -0
  83. data/locales/rails-i18n/iso-639-2/gsw-CH.yml +196 -0
  84. data/locales/rails-i18n/iso-639-2/hsb.yml +207 -0
  85. data/locales/rails-i18n/iso-639-2/pap-AW.yml +205 -0
  86. data/locales/rails-i18n/iso-639-2/pap-CW.yml +205 -0
  87. data/locales/rails-i18n/iso-639-2/scr.yml +236 -0
  88. data/locales/rails-i18n/it-CH.yml +198 -0
  89. data/locales/rails-i18n/it.yml +204 -0
  90. data/locales/rails-i18n/ja.yml +194 -0
  91. data/locales/rails-i18n/km.yml +54 -0
  92. data/locales/rails-i18n/kn.yml +192 -0
  93. data/locales/rails-i18n/ko.yml +190 -0
  94. data/locales/rails-i18n/lo.yml +227 -0
  95. data/locales/rails-i18n/lt.yml +217 -0
  96. data/locales/rails-i18n/lv.yml +229 -0
  97. data/locales/rails-i18n/mk.yml +198 -0
  98. data/locales/rails-i18n/mn.yml +198 -0
  99. data/locales/rails-i18n/ms.yml +200 -0
  100. data/locales/rails-i18n/nb.yml +205 -0
  101. data/locales/rails-i18n/ne.yml +198 -0
  102. data/locales/rails-i18n/nl.yml +204 -0
  103. data/locales/rails-i18n/nn.yml +201 -0
  104. data/locales/rails-i18n/or.yml +192 -0
  105. data/locales/rails-i18n/pl.yml +236 -0
  106. data/locales/rails-i18n/pt-BR.yml +206 -0
  107. data/locales/rails-i18n/pt.yml +200 -0
  108. data/locales/rails-i18n/rm.yml +223 -0
  109. data/locales/rails-i18n/ro.yml +205 -0
  110. data/locales/rails-i18n/ru.yml +256 -0
  111. data/locales/rails-i18n/sk.yml +206 -0
  112. data/locales/rails-i18n/sl.yml +205 -0
  113. data/locales/rails-i18n/sr.yml +236 -0
  114. data/locales/rails-i18n/sv.yml +192 -0
  115. data/locales/rails-i18n/sw.yml +190 -0
  116. data/locales/rails-i18n/ta.yml +204 -0
  117. data/locales/rails-i18n/th.yml +166 -0
  118. data/locales/rails-i18n/tl.yml +224 -0
  119. data/locales/rails-i18n/tr.yml +204 -0
  120. data/locales/rails-i18n/uk.yml +250 -0
  121. data/locales/rails-i18n/ur.yml +204 -0
  122. data/locales/rails-i18n/uz.yml +250 -0
  123. data/locales/rails-i18n/vi.yml +198 -0
  124. data/locales/rails-i18n/wo.yml +198 -0
  125. data/locales/rails-i18n/zh-CN.yml +203 -0
  126. data/locales/rails-i18n/zh-HK.yml +204 -0
  127. data/locales/rails-i18n/zh-TW.yml +203 -0
  128. data/locales/rails-i18n/zh-YUE.yml +204 -0
  129. metadata +164 -74
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d45088b2c65fd274e44926886b8a70f0a645f73
4
+ data.tar.gz: 305ef95bcb2143c71331cfe7e702b97ee9f987f1
5
+ SHA512:
6
+ metadata.gz: 5b4fc64f2b1f57cafa02c21d2392448e64de89648a9ebe54ae06b26b43febcbf5a5b663804c3b7ff3932c5553077ae82be017490ed922ba8571e5c0aaa6ba706
7
+ data.tar.gz: a6ab0937bad9f67492940655bfbcf1e04e9b79c48e5a9ec5761686b25a39d1c2165d0b54d19f76cf470e6e14e8b55edc30b61a446f4ca22ea8a38f49fd423f44
data/LICENSE CHANGED
@@ -1,4 +1,17 @@
1
- GNU AFFERO GENERAL PUBLIC LICENSE
1
+ Licenses
2
+ ========================================
3
+
4
+ Amber code is copyright (c) 2015 LEAP Encrption Access Project and licensed
5
+ under the GNU AGPL, a copy of which is provided below.
6
+
7
+ Additionally, Amber redistributes the localization files from Rails (in
8
+ `amber/locales/rails-i18n/`). These files are copyright (c) 2008-2012 Sven
9
+ Fuchs and contributors (see https://github.com/svenfuchs/rails-
10
+ i18n/contributors), and distributed under an MIT license.
11
+
12
+ GNU Affero General Public License
13
+ ========================================
14
+
2
15
  Version 3, 19 November 2007
3
16
 
4
17
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
data/README.md CHANGED
@@ -1,26 +1,39 @@
1
1
  Amber
2
2
  ===================================
3
3
 
4
- Amber is a super simple and flexible static website generator, with good support for localization and navigation.
4
+ Amber is a super simple and flexible static website generator, with good
5
+ support for localization and navigation.
5
6
 
6
7
  This is still experimental code.
7
8
 
8
- Amber has much in common with other static page generators, but has several features that make it unique:
9
+ Amber has much in common with other static page generators, but has several
10
+ features that make it unique:
9
11
 
10
12
  * I18n: Primary focus is on very good multi-lingual and localization support.
13
+ By using a bunch of Apache tricks, Amber is able to create static websites
14
+ which work more like dynamic sites when it comes to selecting the
15
+ appropriate locale.
11
16
  * Inheritance: Properties are inherited in the page hierarchy.
12
- * TOC: Support for table of contents (including inserting TOC into other pages).
13
- * Flexible: Ability to set custom page path aliases, render partials, rich navigation, and so on.
17
+ * TOC: Support for table of contents (including inserting TOC into other pages,
18
+ and TOC generation from pages generated by a combination of partials and
19
+ different markup languages).
20
+ * Flexible: Ability to set custom page path aliases, render partials, rich
21
+ navigation, and so on.
22
+
23
+ Amber allows ERB (ruby code) in all page markup types, making it unsuitable for
24
+ any website where you do not trust the source of the page text.
14
25
 
15
26
  Installation
16
27
  ---------------------------------
17
28
 
18
29
  Installing from gem:
19
30
 
31
+ sudo apt-get install rubygems ruby-dev build-essential
20
32
  sudo gem install amber
21
33
 
22
- Installing from source:
34
+ Alternately, you can run directly from source:
23
35
 
36
+ sudo apt-get install rubygems ruby-dev build-essential
24
37
  sudo gem install bundler
25
38
  git clone https://github.com/leapcode/amber
26
39
  cd amber
@@ -30,7 +43,8 @@ Installing from source:
30
43
  Directory structure
31
44
  ---------------------------------
32
45
 
33
- A simple website has this structure:
46
+ A simple website has three main folders, `amber`, `pages`, and `public`. For
47
+ example:
34
48
 
35
49
  mysite/
36
50
  amber/
@@ -42,15 +56,20 @@ A simple website has this structure:
42
56
  default.haml
43
57
  pages/
44
58
  page1.en.md
45
- page2.en.md
59
+ page1.de.md
46
60
  public/
47
- page1.en.html
48
- page1.en.html
61
+ page1/
62
+ en.html
63
+ de.html
64
+
65
+ The `public` folder is automatically generated from the `pages` folder.
66
+ Configuration lives in `amber`.
49
67
 
50
- menu.txt
68
+ Menu
51
69
  ---------------------------------
52
70
 
53
- A page does not show up in the navigation unless it appears in menu.txt.
71
+ A page does not show up in the navigation unless it appears in
72
+ `amber/menu.txt`.
54
73
 
55
74
  The order in menu.txt determines the order in the navigation. For example:
56
75
 
@@ -66,7 +85,8 @@ Page hierarchy is represented by two spaces:
66
85
  ddd
67
86
  eee
68
87
 
69
- The items in the menu.txt file must match the names of the pages (the filename with the suffix and locale stripped away).
88
+ The items in the menu.txt file must match the names of the pages (the filename
89
+ with the suffix and locale stripped away).
70
90
 
71
91
  Supported syntaxes
72
92
  ---------------------------------
@@ -76,13 +96,44 @@ Depending the the file extension, the file with be parsed like so:
76
96
  .haml -- HAML
77
97
  .md -- Markdown
78
98
  .markdown -- Markdown
79
- .txt -- Textile
99
+ .text -- Textile
80
100
  .textile -- Textile
81
- .rst -- ReStructuredText
101
+ .html -- HTML
102
+
103
+ You can use the native linking method for each markup, or you can use the
104
+ Amber link method:
105
+
106
+ [[label -> page-name]]
107
+ or
108
+ [[label => page-name]]
109
+ or
110
+ [[label -> absolute-url]]
111
+ or
112
+ [[page-name]]
113
+
114
+ In these examples, `page-name` can be the name of the page, optionally
115
+ qualified by some context. For example, if you had two pages called
116
+ `security`, you could link to `[[chat/security]]` or `[[email/security]]`.
117
+
118
+ This double bracket link notation will automatically find the right
119
+ path for the page with the specified name. Also, Amber will warn you if the page
120
+ name is missing and it will ensure that the link is created with the correct
121
+ language prefix. In haml, you can get the same effect using
122
+ `link 'label' => 'page-name'`
82
123
 
83
- Markdown is rendered using RDiscount, Textile is rendered using RedCloth, and RST is rendered using docutils. Markdown is recommended, because it supports table of contents, although the markup is limited.
124
+ If writing in a right to left script, the links look like:
84
125
 
85
- There are a couple options to preview your source files without needing to run the web server:
126
+ [[page-name <= label]]
127
+
128
+ But only if your text editor correctly displays right to left script.
129
+
130
+ The arrows `->` and `=>` are used interchangeably.
131
+
132
+ Previewing pages
133
+ -------------------------------------
134
+
135
+ To preview your site, run `amber server`. Alternately, there are a couple
136
+ options to preview your source files without needing to run the web server:
86
137
 
87
138
  * Markdown preview for Chrome: https://chrome.google.com/webstore/detail/markdown-preview/jmchmkecamhbiokiopfpnfgbidieafmd
88
139
  * Markdown preview for Sublime: https://github.com/revolunet/sublimetext-markdown-preview
@@ -91,9 +142,7 @@ There are a couple options to preview your source files without needing to run t
91
142
  Setting page properties
92
143
  ---------------------------------
93
144
 
94
- HAML files are rendered as templates, but the other lightweight markup files are treated as static files.
95
-
96
- The one exception is that every file can have a "properties header". It looks like this:
145
+ Every file can have a "properties header". It looks like this:
97
146
 
98
147
  @title = "A fine page"
99
148
  @toc = false
@@ -102,6 +151,13 @@ The one exception is that every file can have a "properties header". It looks li
102
151
 
103
152
  The properties start with '@' and are stripped out of the source file before it is rendered. Property header lines are evaluated as ruby. All properties are optional and they are inherited, including `@title`.
104
153
 
154
+ For haml files, the syntax is slightly different:
155
+
156
+ - @title = "A fine page"
157
+ - @toc = false
158
+
159
+ %p continue on here with body text.
160
+
105
161
  Available properties:
106
162
 
107
163
  * `@title` -- The title for the page, appearing as in an H1 on the top of the page and as the HTML title. Also used for navigation title if `@nav_title` is not set. The inline H1 title does not appear unless `@title` is explicitly set for this page (i.e. the inherited value of `@title` does not trigger the automatic H1).
@@ -112,3 +168,16 @@ Available properties:
112
168
  * `@this.alias` -- Alternate paths for the page to be rendered on. May be an array. The first path will be used when linking.
113
169
 
114
170
  To make a property none-inheritable, specify it like so: `@this.layout = 'home'`. For some properties, like `alias`, it does not make sense for the property to be inheritable.
171
+
172
+ Troubleshooting
173
+ -----------------------------------
174
+
175
+ If you get an error at some point like this:
176
+
177
+ WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.9.1
178
+
179
+ It just means that libxml has been upgraded since the gem nokogiri was installed. To fix, run this:
180
+
181
+ sudo gem pristine nokogiri
182
+
183
+
data/bin/amber CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  if ARGV.include?('--debug')
4
- require 'debugger'
4
+ if RUBY_VERSION =~ /^2/
5
+ require 'byebug'
6
+ else
7
+ require 'debugger'
8
+ end
5
9
  end
6
10
 
7
11
  begin
@@ -25,8 +29,10 @@ def process_command_line_arguments
25
29
  when 'rebuild' then @command = ARGV.shift
26
30
  when 'clean' then @command = 'clear'; ARGV.shift
27
31
  when 'clear' then @command = ARGV.shift
28
- when 'server' then @command = ARGV.shift
29
- when '--port' then ARGV.shift; @port = ARGV.shift
32
+ when 'server' then @command = ARGV.shift; @command_arg = ARGV.shift
33
+ when 'apache' then @command = ARGV.shift; @command_arg = ARGV.shift
34
+ when 'version' then version
35
+ when '--version' then version
30
36
  when '--debug' then ARGV.shift
31
37
  when '--help' then usage
32
38
  when 'help' then usage
@@ -45,21 +51,28 @@ def usage(msg=nil)
45
51
  $stderr.puts("Usage: #{File.basename($0)} [OPTIONS] COMMAND")
46
52
  $stderr.puts
47
53
  $stderr.puts("COMMAND may be one or more of:
48
- init DIRECTORY -- create a new amber site in DIRECTORY
49
- build -- render static html pages
50
- rebuild -- runs `clear` then `build`
51
- server -- runs mini-web server at localhost:8000
52
- clear -- erase static html pages
53
- clean -- alias for clear
54
- help -- this message")
54
+ init DIRECTORY -- Create a new amber site in DIRECTORY.
55
+ build -- Render static html pages.
56
+ rebuild -- Runs `clear` then `build`.
57
+ server [[HOST][:PORT]] -- Runs mini web server bound to HOST:PORT (defaults to #{Amber::DEFAULT_HOST}:#{Amber::DEFAULT_PORT}).
58
+ clear -- Erase static HTML pages.
59
+ clean -- Alias for `clear`.
60
+ apache DIRECTORY -- Prints out appropriate apache2 config for the given DIRECTORY.
61
+ help -- This message.
62
+ version -- Print version and exit.")
55
63
  $stderr.puts
56
64
  $stderr.puts("OPTIONS may be one or more of:
57
- -v -- run in verbose mode
58
- --debug -- enable debugger
59
- --port PORT -- sets the port for the `server` command (default 8000)")
65
+ -v -- Run in verbose mode.
66
+ --version -- Print version and exit.
67
+ --debug -- Enable debugger.")
60
68
  exit(2)
61
69
  end
62
70
 
71
+ def version
72
+ puts Amber::VERSION
73
+ exit
74
+ end
75
+
63
76
  def main
64
77
  process_command_line_arguments
65
78
  if @verbose
@@ -1,60 +1,45 @@
1
1
  # encoding: utf-8
2
2
 
3
+ # enforce UTF8 as the default, even if LANG environment
4
+ # variable says otherwise.
5
+ Encoding.default_internal = Encoding::UTF_8
6
+ Encoding.default_external = Encoding::UTF_8
7
+
3
8
  require 'logger'
4
- require 'i18n'
5
- require 'i18n/backend/fallbacks'
6
- I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
7
9
 
8
- require 'sass' # sass seems to freak out if require'd after haml.
9
- require 'haml' #
10
+ # ensure that we load sass from a gem, not the sass included in some
11
+ # versions of haml.
12
+ gem 'sass'
13
+ require 'sass'
14
+ require 'haml'
10
15
 
11
16
  module Amber
12
17
 
13
18
  class MissingTemplate < StandardError
14
19
  end
15
20
 
16
- #
17
- # Languages that might possibly be supported.
18
- #
19
- # https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers
20
- #
21
- POSSIBLE_LANGUAGES = {
22
- :zh => ['中文', 'zh', 1, false],
23
- :es => ['Español', 'es', 2, false],
24
- :en => ['English', 'en', 3, false],
25
- :hi => ['Hindi', 'hi', 4, false],
26
- :ar => ['العربية', 'ar', 5, true],
27
- :pt => ['Português', 'pt', 6, false],
28
- :ru => ['Pyccĸий', 'ru', 7, false],
29
- :de => ['Deutsch', 'de', 8, false],
30
- :fr => ['Français', 'fr', 10, false],
31
- :it => ['Italiano', 'it', 11, false],
32
- :el => ['Ελληνικά', 'el', 20, false],
33
- :ca => ['Català', 'ca', 101, false]
34
- }
35
-
36
- # Although everywhere else we use symbols for locales, this array should be strings:
37
- POSSIBLE_LANGUAGE_CODES = POSSIBLE_LANGUAGES.keys.map(&:to_s)
38
-
39
21
  # Possible page suffixes. Only files with these suffixes are treated as pages
40
- PAGE_SUFFIXES = %w(haml md markdown text textile rst html)
41
-
42
- def self.logger
43
- @logger ||= begin
44
- logger = Logger.new(STDOUT)
45
- logger.level = Logger::INFO
46
- logger.formatter = proc do |severity, datetime, progname, msg|
47
- "#{severity}: #{msg}\n"
48
- end
49
- logger
22
+ PAGE_SUFFIXES = %w(haml md markdown text textile rst html html.haml)
23
+
24
+ DEFAULT_HOST = '127.0.0.1'
25
+ DEFAULT_PORT = '8000'
26
+
27
+ def self.env
28
+ if defined?(TESTING) && TESTING==true
29
+ :test
30
+ elsif defined?(Amber::Server)
31
+ :developmet
32
+ else
33
+ :production
50
34
  end
51
35
  end
52
36
 
53
37
  end
54
38
 
39
+ require 'amber/version'
55
40
  require 'amber/cli'
56
- require 'amber/server'
57
41
  require 'amber/logger'
42
+ require 'amber/i18n'
58
43
 
59
44
  require 'amber/menu'
60
45
  require 'amber/site'
@@ -74,3 +59,4 @@ require 'amber/render/asset'
74
59
  require 'amber/render/autolink'
75
60
  require 'amber/render/bracketlink'
76
61
  require 'amber/render/table_of_contents'
62
+ require 'amber/render/apache'
@@ -40,6 +40,7 @@ module Amber
40
40
  site = Site.new(@root)
41
41
  site.continue_on_error = false
42
42
  site.load_pages
43
+ FileUtils.mkdir_p(site.dest_dir) unless File.exists?(site.dest_dir)
43
44
  gitkeep = File.exists?(File.join(site.dest_dir, '.gitkeep'))
44
45
  temp_render = File.join(File.dirname(site.dest_dir), 'public-tmp')
45
46
  temp_old_pages = File.join(File.dirname(site.dest_dir), 'remove-me')
@@ -62,8 +63,31 @@ module Amber
62
63
  end
63
64
 
64
65
  def server(options)
66
+ require 'amber/server'
67
+ host = nil
68
+ port = nil
69
+ if options[:arg]
70
+ host, port = options[:arg].split(':')
71
+ end
72
+ if host.nil? || host.empty?
73
+ host = DEFAULT_HOST
74
+ end
75
+ if port.nil? || port.empty?
76
+ port = DEFAULT_PORT
77
+ end
65
78
  site = Site.new(@root)
66
- Amber::Server.start(:port => (options[:port] || 8000), :site => site)
79
+ Amber::Server.start(:port => port, :host => host, :site => site)
80
+ end
81
+
82
+ def apache(options)
83
+ site = Site.new(@root)
84
+ directory = options[:arg]
85
+ unless directory
86
+ puts "Missing DIRECTORY argument"
87
+ exit 1
88
+ end
89
+ directory = directory.gsub(%r{^/|/$}, '')
90
+ Amber::Render::Apache.echo_config(site, directory)
67
91
  end
68
92
 
69
93
  private
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'i18n'
4
+ require 'i18n/backend/fallbacks'
5
+
6
+ I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
7
+ I18n.enforce_available_locales = false
8
+
9
+ I18n.load_path += Dir[File.join(File.expand_path('../../../locales', __FILE__), '/**/*.{yml,yaml}')]
10
+
11
+ module Amber
12
+
13
+ #
14
+ # Languages that might possibly be supported.
15
+ #
16
+ # https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers
17
+ #
18
+ POSSIBLE_LANGUAGES = {
19
+ :zh => ['中文', 'zh', 1, false], # Chinese
20
+ :es => ['Español', 'es', 2, false],
21
+ :en => ['English', 'en', 3, false],
22
+ :hi => ['Hindi', 'hi', 4, false],
23
+ :ar => ['العربية', 'ar', 5, true], # Arabic
24
+ :pt => ['Português', 'pt', 6, false],
25
+ :ru => ['Pyccĸий', 'ru', 7, false], # Russian
26
+ :ja => ['日本語', 'ja', 8, false], # Japanese
27
+ :pa => ['ਪੰਜਾਬੀ', 'pa', 9, false], # Punjabi
28
+ :de => ['Deutsch', 'de', 10, false],
29
+ :vi => ['Tiếng Việt','vi', 11, false], # Vietnamese
30
+ :fr => ['Français', 'fr', 12, false],
31
+ :ur => ['اُردُو', 'ur', 13, false], # Urdu
32
+ :fa => ['فارسی', 'fa', 14, false], # Farsi / Persian
33
+ :tr => ['Türkçe', 'tr', 15, false], # Turkish
34
+ :it => ['Italiano', 'it', 16, false],
35
+ :el => ['Ελληνικά', 'el', 17, false], # Greek
36
+ :pl => ['Polski', 'pl', 18, false], # Polish
37
+ :ca => ['Català', 'ca', 19, false]
38
+ }
39
+
40
+ # Although everywhere else we use symbols for locales, this array should be strings:
41
+ POSSIBLE_LANGUAGE_CODES = POSSIBLE_LANGUAGES.keys.map(&:to_s)
42
+
43
+ end
@@ -0,0 +1,44 @@
1
+ module Amber
2
+ module Render
3
+ class Apache
4
+
5
+ def self.write_htaccess(site, src_dir, dst_dir)
6
+ src_htaccess_file = File.join(src_dir, '.htaccess')
7
+ dst_htaccess_file = File.join(dst_dir, '.htaccess')
8
+ template = Tilt::ERBTemplate.new(template_path("htaccess.erb"))
9
+
10
+ tail_content = nil
11
+ if File.exists?(src_htaccess_file)
12
+ tail_content = File.read(src_htaccess_file)
13
+ end
14
+ File.open(dst_htaccess_file, 'w', :encoding => 'UTF-8') do |f|
15
+ f.write template.render(context_object(:site => site))
16
+ if tail_content
17
+ f.write "\n\n"
18
+ f.write tail_content
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.echo_config(site, directory)
24
+ template = Tilt::ERBTemplate.new(
25
+ site.path_prefix ? template_path('apache_config_with_prefix.erb') : template_path('apache_config.erb')
26
+ )
27
+ puts template.render(context_object(:site => site, :directory => directory))
28
+ end
29
+
30
+ def self.context_object(variables)
31
+ object = Object.new
32
+ variables.each do |name, value|
33
+ object.instance_variable_set("@#{name}", value)
34
+ end
35
+ object
36
+ end
37
+
38
+ def self.template_path(filename)
39
+ File.expand_path("../templates/#{filename}", File.dirname(__FILE__))
40
+ end
41
+
42
+ end
43
+ end
44
+ end