tabulous 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/CHANGELOG.rdoc +2 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +21 -0
- data/README.rdoc +85 -0
- data/Rakefile +54 -0
- data/lib/generators/tabs/USAGE +1 -0
- data/lib/generators/tabs/tabs_generator.rb +13 -0
- data/lib/generators/tabs/templates/tabulous.rb +170 -0
- data/lib/tabulous.rb +11 -0
- data/lib/tabulous/css_scaffolding.rb +111 -0
- data/lib/tabulous/errors.rb +16 -0
- data/lib/tabulous/formatter.rb +278 -0
- data/lib/tabulous/helpers.rb +13 -0
- data/lib/tabulous/options.rb +37 -0
- data/lib/tabulous/railtie.rb +23 -0
- data/lib/tabulous/tab.rb +79 -0
- data/lib/tabulous/tabulous.rb +162 -0
- data/lib/tabulous/version.rb +3 -0
- data/lib/tasks/tabulous.rake +11 -0
- data/tabulous.gemspec +30 -0
- data/test/applications/main/.gitignore +3 -0
- data/test/applications/main/Gemfile +7 -0
- data/test/applications/main/Rakefile +7 -0
- data/test/applications/main/app/controllers/application_controller.rb +3 -0
- data/test/applications/main/app/controllers/galaxies_controller.rb +83 -0
- data/test/applications/main/app/controllers/home_controller.rb +4 -0
- data/test/applications/main/app/controllers/planets_controller.rb +83 -0
- data/test/applications/main/app/controllers/stars_controller.rb +83 -0
- data/test/applications/main/app/controllers/subtabs_controller.rb +8 -0
- data/test/applications/main/app/helpers/application_helper.rb +2 -0
- data/test/applications/main/app/helpers/galaxies_helper.rb +2 -0
- data/test/applications/main/app/helpers/planets_helper.rb +2 -0
- data/test/applications/main/app/helpers/stars_helper.rb +2 -0
- data/test/applications/main/app/models/galaxy.rb +2 -0
- data/test/applications/main/app/models/planet.rb +2 -0
- data/test/applications/main/app/models/star.rb +2 -0
- data/test/applications/main/app/views/galaxies/_form.html.erb +21 -0
- data/test/applications/main/app/views/galaxies/edit.html.erb +6 -0
- data/test/applications/main/app/views/galaxies/index.html.erb +23 -0
- data/test/applications/main/app/views/galaxies/new.html.erb +5 -0
- data/test/applications/main/app/views/galaxies/show.html.erb +10 -0
- data/test/applications/main/app/views/home/index.html.erb +3 -0
- data/test/applications/main/app/views/layouts/application.html.erb +16 -0
- data/test/applications/main/app/views/planets/_form.html.erb +21 -0
- data/test/applications/main/app/views/planets/edit.html.erb +6 -0
- data/test/applications/main/app/views/planets/index.html.erb +23 -0
- data/test/applications/main/app/views/planets/new.html.erb +5 -0
- data/test/applications/main/app/views/planets/show.html.erb +10 -0
- data/test/applications/main/app/views/stars/_form.html.erb +21 -0
- data/test/applications/main/app/views/stars/edit.html.erb +6 -0
- data/test/applications/main/app/views/stars/index.html.erb +23 -0
- data/test/applications/main/app/views/stars/new.html.erb +5 -0
- data/test/applications/main/app/views/stars/show.html.erb +10 -0
- data/test/applications/main/app/views/subtabs/one.html.erb +1 -0
- data/test/applications/main/app/views/subtabs/three.html.erb +1 -0
- data/test/applications/main/app/views/subtabs/two.html.erb +1 -0
- data/test/applications/main/config.ru +4 -0
- data/test/applications/main/config/application.rb +42 -0
- data/test/applications/main/config/boot.rb +13 -0
- data/test/applications/main/config/database.yml +22 -0
- data/test/applications/main/config/environment.rb +5 -0
- data/test/applications/main/config/environments/development.rb +26 -0
- data/test/applications/main/config/environments/production.rb +49 -0
- data/test/applications/main/config/environments/test.rb +35 -0
- data/test/applications/main/config/initializers/backtrace_silencers.rb +7 -0
- data/test/applications/main/config/initializers/inflections.rb +10 -0
- data/test/applications/main/config/initializers/mime_types.rb +5 -0
- data/test/applications/main/config/initializers/secret_token.rb +7 -0
- data/test/applications/main/config/initializers/session_store.rb +8 -0
- data/test/applications/main/config/initializers/tabulous.rb +156 -0
- data/test/applications/main/config/locales/en.yml +5 -0
- data/test/applications/main/config/routes.rb +69 -0
- data/test/applications/main/db/development.sqlite3 +0 -0
- data/test/applications/main/db/migrate/20110223232547_create_galaxies.rb +13 -0
- data/test/applications/main/db/migrate/20110223232552_create_stars.rb +13 -0
- data/test/applications/main/db/migrate/20110223232557_create_planets.rb +13 -0
- data/test/applications/main/db/production.sqlite3 +0 -0
- data/test/applications/main/db/schema.rb +33 -0
- data/test/applications/main/db/test.sqlite3 +0 -0
- data/test/applications/main/public/404.html +26 -0
- data/test/applications/main/public/422.html +26 -0
- data/test/applications/main/public/500.html +26 -0
- data/test/applications/main/public/favicon.ico +0 -0
- data/test/applications/main/public/javascripts/application.js +2 -0
- data/test/applications/main/public/javascripts/controls.js +965 -0
- data/test/applications/main/public/javascripts/dragdrop.js +974 -0
- data/test/applications/main/public/javascripts/effects.js +1123 -0
- data/test/applications/main/public/javascripts/prototype.js +6001 -0
- data/test/applications/main/public/javascripts/rails.js +175 -0
- data/test/applications/main/public/stylesheets/.gitkeep +0 -0
- data/test/applications/main/script/rails +6 -0
- data/test/applications/main/test/integration/actions_test.rb +79 -0
- data/test/applications/main/test/integration/active_tab_clickable_test.rb +86 -0
- data/test/applications/main/test/integration/always_render_subtabs_test.rb +84 -0
- data/test/applications/main/test/integration/css_no_scaffolding_test.rb +57 -0
- data/test/applications/main/test/integration/css_scaffolding_test.rb +67 -0
- data/test/applications/main/test/integration/display_text_test.rb +73 -0
- data/test/applications/main/test/integration/enabled_test.rb +80 -0
- data/test/applications/main/test/integration/html5_test.rb +64 -0
- data/test/applications/main/test/integration/main_tabs_test.rb +10 -0
- data/test/applications/main/test/integration/path_test.rb +81 -0
- data/test/applications/main/test/integration/visible_test.rb +80 -0
- data/test/applications/main/test/integration_test_helper.rb +6 -0
- data/test/applications/main/test/test_helper.rb +8 -0
- data/test/applications/main/test/unit/tabs_generator_test.rb +14 -0
- data/test/applications/simple_tabs/.gitignore +3 -0
- data/test/applications/simple_tabs/Gemfile +7 -0
- data/test/applications/simple_tabs/Rakefile +7 -0
- data/test/applications/simple_tabs/app/controllers/application_controller.rb +3 -0
- data/test/applications/simple_tabs/app/controllers/galaxies_controller.rb +83 -0
- data/test/applications/simple_tabs/app/controllers/home_controller.rb +4 -0
- data/test/applications/simple_tabs/app/controllers/planets_controller.rb +83 -0
- data/test/applications/simple_tabs/app/controllers/stars_controller.rb +83 -0
- data/test/applications/simple_tabs/app/helpers/application_helper.rb +2 -0
- data/test/applications/simple_tabs/app/helpers/galaxies_helper.rb +2 -0
- data/test/applications/simple_tabs/app/helpers/planets_helper.rb +2 -0
- data/test/applications/simple_tabs/app/helpers/stars_helper.rb +2 -0
- data/test/applications/simple_tabs/app/models/galaxy.rb +2 -0
- data/test/applications/simple_tabs/app/models/planet.rb +2 -0
- data/test/applications/simple_tabs/app/models/star.rb +2 -0
- data/test/applications/simple_tabs/app/views/galaxies/_form.html.erb +21 -0
- data/test/applications/simple_tabs/app/views/galaxies/edit.html.erb +6 -0
- data/test/applications/simple_tabs/app/views/galaxies/index.html.erb +23 -0
- data/test/applications/simple_tabs/app/views/galaxies/new.html.erb +5 -0
- data/test/applications/simple_tabs/app/views/galaxies/show.html.erb +10 -0
- data/test/applications/simple_tabs/app/views/home/index.html.erb +4 -0
- data/test/applications/simple_tabs/app/views/layouts/application.html.erb +16 -0
- data/test/applications/simple_tabs/app/views/planets/_form.html.erb +21 -0
- data/test/applications/simple_tabs/app/views/planets/edit.html.erb +6 -0
- data/test/applications/simple_tabs/app/views/planets/index.html.erb +23 -0
- data/test/applications/simple_tabs/app/views/planets/new.html.erb +5 -0
- data/test/applications/simple_tabs/app/views/planets/show.html.erb +10 -0
- data/test/applications/simple_tabs/app/views/stars/_form.html.erb +21 -0
- data/test/applications/simple_tabs/app/views/stars/edit.html.erb +6 -0
- data/test/applications/simple_tabs/app/views/stars/index.html.erb +23 -0
- data/test/applications/simple_tabs/app/views/stars/new.html.erb +5 -0
- data/test/applications/simple_tabs/app/views/stars/show.html.erb +10 -0
- data/test/applications/simple_tabs/config.ru +4 -0
- data/test/applications/simple_tabs/config/application.rb +42 -0
- data/test/applications/simple_tabs/config/boot.rb +13 -0
- data/test/applications/simple_tabs/config/database.yml +22 -0
- data/test/applications/simple_tabs/config/environment.rb +5 -0
- data/test/applications/simple_tabs/config/environments/development.rb +26 -0
- data/test/applications/simple_tabs/config/environments/production.rb +49 -0
- data/test/applications/simple_tabs/config/environments/test.rb +35 -0
- data/test/applications/simple_tabs/config/initializers/backtrace_silencers.rb +7 -0
- data/test/applications/simple_tabs/config/initializers/inflections.rb +10 -0
- data/test/applications/simple_tabs/config/initializers/mime_types.rb +5 -0
- data/test/applications/simple_tabs/config/initializers/secret_token.rb +7 -0
- data/test/applications/simple_tabs/config/initializers/session_store.rb +8 -0
- data/test/applications/simple_tabs/config/initializers/tabulous.rb +149 -0
- data/test/applications/simple_tabs/config/locales/en.yml +5 -0
- data/test/applications/simple_tabs/config/routes.rb +65 -0
- data/test/applications/simple_tabs/db/development.sqlite3 +0 -0
- data/test/applications/simple_tabs/db/migrate/20110220170240_create_galaxies.rb +13 -0
- data/test/applications/simple_tabs/db/migrate/20110220170245_create_stars.rb +13 -0
- data/test/applications/simple_tabs/db/migrate/20110220170250_create_planets.rb +13 -0
- data/test/applications/simple_tabs/db/production.sqlite3 +0 -0
- data/test/applications/simple_tabs/db/schema.rb +33 -0
- data/test/applications/simple_tabs/db/test.sqlite3 +0 -0
- data/test/applications/simple_tabs/public/404.html +26 -0
- data/test/applications/simple_tabs/public/422.html +26 -0
- data/test/applications/simple_tabs/public/500.html +26 -0
- data/test/applications/simple_tabs/public/favicon.ico +0 -0
- data/test/applications/simple_tabs/public/javascripts/application.js +2 -0
- data/test/applications/simple_tabs/public/javascripts/controls.js +965 -0
- data/test/applications/simple_tabs/public/javascripts/dragdrop.js +974 -0
- data/test/applications/simple_tabs/public/javascripts/effects.js +1123 -0
- data/test/applications/simple_tabs/public/javascripts/prototype.js +6001 -0
- data/test/applications/simple_tabs/public/javascripts/rails.js +175 -0
- data/test/applications/simple_tabs/public/stylesheets/.gitkeep +0 -0
- data/test/applications/simple_tabs/script/rails +6 -0
- data/test/applications/simple_tabs/test/integration/simple_tabs_test.rb +34 -0
- data/test/applications/simple_tabs/test/integration_test_helper.rb +6 -0
- data/test/applications/simple_tabs/test/test_helper.rb +8 -0
- data/test/applications/subtabs/.gitignore +3 -0
- data/test/applications/subtabs/Gemfile +7 -0
- data/test/applications/subtabs/Rakefile +7 -0
- data/test/applications/subtabs/app/controllers/application_controller.rb +3 -0
- data/test/applications/subtabs/app/controllers/exoplanets_controller.rb +83 -0
- data/test/applications/subtabs/app/controllers/galaxies/elliptical_galaxies_controller.rb +85 -0
- data/test/applications/subtabs/app/controllers/galaxies/lenticular_galaxies_controller.rb +85 -0
- data/test/applications/subtabs/app/controllers/galaxies/spiral_galaxies_controller.rb +85 -0
- data/test/applications/subtabs/app/controllers/home_controller.rb +4 -0
- data/test/applications/subtabs/app/controllers/misc_controller.rb +15 -0
- data/test/applications/subtabs/app/controllers/rogue_planets_controller.rb +83 -0
- data/test/applications/subtabs/app/controllers/stars_controller.rb +83 -0
- data/test/applications/subtabs/app/helpers/application_helper.rb +2 -0
- data/test/applications/subtabs/app/helpers/elliptical_galaxies_helper.rb +2 -0
- data/test/applications/subtabs/app/helpers/exoplanets_helper.rb +2 -0
- data/test/applications/subtabs/app/helpers/lenticular_galaxies_helper.rb +2 -0
- data/test/applications/subtabs/app/helpers/rogue_planets_helper.rb +2 -0
- data/test/applications/subtabs/app/helpers/spiral_galaxies_helper.rb +2 -0
- data/test/applications/subtabs/app/helpers/stars_helper.rb +2 -0
- data/test/applications/subtabs/app/models/elliptical_galaxy.rb +2 -0
- data/test/applications/subtabs/app/models/exoplanet.rb +2 -0
- data/test/applications/subtabs/app/models/lenticular_galaxy.rb +2 -0
- data/test/applications/subtabs/app/models/rogue_planet.rb +2 -0
- data/test/applications/subtabs/app/models/spiral_galaxy.rb +2 -0
- data/test/applications/subtabs/app/models/star.rb +2 -0
- data/test/applications/subtabs/app/views/exoplanets/_form.html.erb +21 -0
- data/test/applications/subtabs/app/views/exoplanets/edit.html.erb +6 -0
- data/test/applications/subtabs/app/views/exoplanets/index.html.erb +23 -0
- data/test/applications/subtabs/app/views/exoplanets/new.html.erb +5 -0
- data/test/applications/subtabs/app/views/exoplanets/show.html.erb +10 -0
- data/test/applications/subtabs/app/views/galaxies/elliptical_galaxies/_form.html.erb +21 -0
- data/test/applications/subtabs/app/views/galaxies/elliptical_galaxies/edit.html.erb +6 -0
- data/test/applications/subtabs/app/views/galaxies/elliptical_galaxies/index.html.erb +23 -0
- data/test/applications/subtabs/app/views/galaxies/elliptical_galaxies/new.html.erb +5 -0
- data/test/applications/subtabs/app/views/galaxies/elliptical_galaxies/show.html.erb +10 -0
- data/test/applications/subtabs/app/views/galaxies/lenticular_galaxies/_form.html.erb +21 -0
- data/test/applications/subtabs/app/views/galaxies/lenticular_galaxies/edit.html.erb +6 -0
- data/test/applications/subtabs/app/views/galaxies/lenticular_galaxies/index.html.erb +23 -0
- data/test/applications/subtabs/app/views/galaxies/lenticular_galaxies/new.html.erb +5 -0
- data/test/applications/subtabs/app/views/galaxies/lenticular_galaxies/show.html.erb +10 -0
- data/test/applications/subtabs/app/views/galaxies/spiral_galaxies/_form.html.erb +21 -0
- data/test/applications/subtabs/app/views/galaxies/spiral_galaxies/edit.html.erb +6 -0
- data/test/applications/subtabs/app/views/galaxies/spiral_galaxies/index.html.erb +23 -0
- data/test/applications/subtabs/app/views/galaxies/spiral_galaxies/new.html.erb +5 -0
- data/test/applications/subtabs/app/views/galaxies/spiral_galaxies/show.html.erb +10 -0
- data/test/applications/subtabs/app/views/home/index.html.erb +14 -0
- data/test/applications/subtabs/app/views/layouts/application.html.erb +21 -0
- data/test/applications/subtabs/app/views/misc/always_enabled.html.erb +4 -0
- data/test/applications/subtabs/app/views/misc/always_visible.html.erb +4 -0
- data/test/applications/subtabs/app/views/rogue_planets/_form.html.erb +21 -0
- data/test/applications/subtabs/app/views/rogue_planets/edit.html.erb +6 -0
- data/test/applications/subtabs/app/views/rogue_planets/index.html.erb +23 -0
- data/test/applications/subtabs/app/views/rogue_planets/new.html.erb +5 -0
- data/test/applications/subtabs/app/views/rogue_planets/show.html.erb +10 -0
- data/test/applications/subtabs/app/views/stars/_form.html.erb +21 -0
- data/test/applications/subtabs/app/views/stars/edit.html.erb +6 -0
- data/test/applications/subtabs/app/views/stars/index.html.erb +23 -0
- data/test/applications/subtabs/app/views/stars/new.html.erb +5 -0
- data/test/applications/subtabs/app/views/stars/show.html.erb +10 -0
- data/test/applications/subtabs/config.ru +4 -0
- data/test/applications/subtabs/config/application.rb +42 -0
- data/test/applications/subtabs/config/boot.rb +13 -0
- data/test/applications/subtabs/config/database.yml +22 -0
- data/test/applications/subtabs/config/environment.rb +5 -0
- data/test/applications/subtabs/config/environments/development.rb +26 -0
- data/test/applications/subtabs/config/environments/production.rb +49 -0
- data/test/applications/subtabs/config/environments/test.rb +35 -0
- data/test/applications/subtabs/config/initializers/backtrace_silencers.rb +7 -0
- data/test/applications/subtabs/config/initializers/inflections.rb +10 -0
- data/test/applications/subtabs/config/initializers/mime_types.rb +5 -0
- data/test/applications/subtabs/config/initializers/secret_token.rb +7 -0
- data/test/applications/subtabs/config/initializers/session_store.rb +8 -0
- data/test/applications/subtabs/config/initializers/tabulous.rb +167 -0
- data/test/applications/subtabs/config/locales/en.yml +5 -0
- data/test/applications/subtabs/config/routes.rb +74 -0
- data/test/applications/subtabs/db/development.sqlite3 +0 -0
- data/test/applications/subtabs/db/migrate/20110223220628_create_galaxies.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110223220634_create_stars.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110223220640_create_planets.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110226190125_create_rogue_planets.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110226190131_create_exoplanets.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110226190532_create_spiral_galaxies.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110226190537_create_lenticular_galaxies.rb +13 -0
- data/test/applications/subtabs/db/migrate/20110226190543_create_elliptical_galaxies.rb +13 -0
- data/test/applications/subtabs/db/production.sqlite3 +0 -0
- data/test/applications/subtabs/db/schema.rb +63 -0
- data/test/applications/subtabs/db/test.sqlite3 +0 -0
- data/test/applications/subtabs/public/404.html +26 -0
- data/test/applications/subtabs/public/422.html +26 -0
- data/test/applications/subtabs/public/500.html +26 -0
- data/test/applications/subtabs/public/favicon.ico +0 -0
- data/test/applications/subtabs/public/javascripts/application.js +2 -0
- data/test/applications/subtabs/public/javascripts/controls.js +965 -0
- data/test/applications/subtabs/public/javascripts/dragdrop.js +974 -0
- data/test/applications/subtabs/public/javascripts/effects.js +1123 -0
- data/test/applications/subtabs/public/javascripts/prototype.js +6001 -0
- data/test/applications/subtabs/public/javascripts/rails.js +175 -0
- data/test/applications/subtabs/public/stylesheets/.gitkeep +0 -0
- data/test/applications/subtabs/public/stylesheets/application.css +49 -0
- data/test/applications/subtabs/public/stylesheets/reset.css +48 -0
- data/test/applications/subtabs/script/rails +6 -0
- data/test/applications/subtabs/test/integration/subtabs_test.rb +67 -0
- data/test/applications/subtabs/test/integration_test_helper.rb +6 -0
- data/test/applications/subtabs/test/test_helper.rb +8 -0
- data/test/test_application_gemfile.rb +14 -0
- data/test/test_application_integration_test_helper.rb +89 -0
- data/test/test_application_test_helper.rb +11 -0
- data/test/test_initializers/empty +0 -0
- data/test/test_initializers/expected +55 -0
- data/test/test_initializers/random_horizontal_whitespace +55 -0
- data/test/test_initializers/random_vertical_whitespace +102 -0
- data/test/test_initializers/text +144 -0
- data/test/test_initializers/trailing_comments +55 -0
- data/test/unit_test_helper.rb +13 -0
- data/test/units/tabulous_formatter_test.rb +69 -0
- metadata +466 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Tabulous
|
|
2
|
+
|
|
3
|
+
class TabulousError < StandardError
|
|
4
|
+
def initialize(msg=nil)
|
|
5
|
+
msg = "Tabulous Error: #{msg}"
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class ColumnError < TabulousError; end
|
|
11
|
+
class NoTabFoundError < TabulousError; end
|
|
12
|
+
class UnknownTabError < TabulousError; end
|
|
13
|
+
class TabNameError < TabulousError; end
|
|
14
|
+
class FormattingError < TabulousError; end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
require 'active_support/core_ext/string'
|
|
2
|
+
|
|
3
|
+
module Tabulous
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Formatter
|
|
8
|
+
def self.format(lines)
|
|
9
|
+
Parser.new(lines).go
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Parser
|
|
16
|
+
|
|
17
|
+
def initialize(lines)
|
|
18
|
+
@input_lines = lines
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def go
|
|
22
|
+
output_lines = []
|
|
23
|
+
@current_table = nil
|
|
24
|
+
@input_lines.each do |input_line|
|
|
25
|
+
line = Line.new(input_line)
|
|
26
|
+
if @current_table && line.end_of_table?
|
|
27
|
+
output_lines += Prettifier.new(@current_table).prettify
|
|
28
|
+
@current_table = nil
|
|
29
|
+
end
|
|
30
|
+
if @current_table
|
|
31
|
+
at_start_of_header = (@current_table.indentation.nil? && line.horizontal_rule?)
|
|
32
|
+
at_top_header_row = @current_table.header_row.empty? && line.header_row?
|
|
33
|
+
at_bottom_header_row = !@current_table.header_row.empty? && line.header_row?
|
|
34
|
+
if at_start_of_header
|
|
35
|
+
@current_table.indentation = line.indentation
|
|
36
|
+
elsif at_top_header_row
|
|
37
|
+
@current_table.header_row = line.header_row
|
|
38
|
+
elsif line.table_row?
|
|
39
|
+
@current_table.add_row(*line.table_row)
|
|
40
|
+
elsif line.blank?
|
|
41
|
+
# blank lines go away
|
|
42
|
+
elsif line.horizontal_rule?
|
|
43
|
+
# we can also safely ignore header lines as they will be regenerated
|
|
44
|
+
elsif at_bottom_header_row
|
|
45
|
+
# we can also safely ignore this as it will be regenerated
|
|
46
|
+
else
|
|
47
|
+
raise FormattingError,
|
|
48
|
+
"Only properly formatted table rows expected. " +
|
|
49
|
+
"For example, comments can only appear at the end of table rows, not " +
|
|
50
|
+
"between them. Aborting."
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
output_lines << line.text
|
|
54
|
+
end
|
|
55
|
+
if !@current_table && line.beginning_of_table?
|
|
56
|
+
@current_table = Table.new
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
return output_lines
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Table
|
|
67
|
+
|
|
68
|
+
attr_reader :header_row, :end_of_row_comments, :rows
|
|
69
|
+
attr_accessor :indentation
|
|
70
|
+
|
|
71
|
+
def initialize
|
|
72
|
+
@rows = []
|
|
73
|
+
@header_row = []
|
|
74
|
+
@end_of_row_comments = []
|
|
75
|
+
@indentation = nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def header_row=(val)
|
|
79
|
+
@header_row = val
|
|
80
|
+
calculate_column_widths
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def add_row(cells, end_of_row_comment)
|
|
84
|
+
@rows << cells
|
|
85
|
+
@end_of_row_comments << end_of_row_comment
|
|
86
|
+
calculate_column_widths
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def column_width(column_number)
|
|
90
|
+
@column_widths[column_number]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def number_of_columns
|
|
94
|
+
@header_row.size
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
99
|
+
def calculate_column_widths
|
|
100
|
+
@column_widths = {}
|
|
101
|
+
for column in (0..number_of_columns-1)
|
|
102
|
+
column_cells = [@header_row[column]]
|
|
103
|
+
row_number = 0
|
|
104
|
+
column_cells += @rows.map do |row|
|
|
105
|
+
row_number += 1
|
|
106
|
+
if row[column].nil?
|
|
107
|
+
raise FormattingError,
|
|
108
|
+
"There appears to be at least one missing table cell, probably " +
|
|
109
|
+
"in row ##{row_number}, column ##{column+1}. Remember that commas " +
|
|
110
|
+
"that separate table cells must be surrounded by spaces or " +
|
|
111
|
+
"the formatter gets confused."
|
|
112
|
+
else
|
|
113
|
+
row[column]
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
@column_widths[column] = column_cells.map(&:length).max
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class Line
|
|
125
|
+
|
|
126
|
+
def initialize(line)
|
|
127
|
+
@line = line
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def text
|
|
131
|
+
@line
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def beginning_of_table?
|
|
135
|
+
line = @line.split('#').first # naively strip out comments
|
|
136
|
+
return false if line.nil?
|
|
137
|
+
line = line.gsub(/\s/, '')
|
|
138
|
+
return line == 'config.tabs=[' || line == 'config.actions=['
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def end_of_table?
|
|
142
|
+
line = @line.split('#').first # naively strip out comments
|
|
143
|
+
return false if line.nil?
|
|
144
|
+
line = line.gsub(/\s/, '')
|
|
145
|
+
return line == ']'
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def horizontal_rule?
|
|
149
|
+
@line =~ /^(\s*)#--/
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def header_row?
|
|
153
|
+
stripped_line = @line.strip
|
|
154
|
+
stripped_line.starts_with?('# ') && stripped_line.slice('|')
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def table_row?
|
|
158
|
+
stripped_line = @line.strip
|
|
159
|
+
stripped_line.starts_with?('[')
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def blank?
|
|
163
|
+
@line.strip.blank?
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def indentation
|
|
167
|
+
@line =~ /^(\s*)\S+/
|
|
168
|
+
$1.size
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def header_row
|
|
172
|
+
return nil unless header_row?
|
|
173
|
+
cells = @line.strip.split('|')
|
|
174
|
+
first_cell = cells.shift
|
|
175
|
+
first_cell = first_cell.split('#').last.strip
|
|
176
|
+
last_cell = cells.pop
|
|
177
|
+
if last_cell =~ /#\s*\S+/
|
|
178
|
+
raise FormattingError,
|
|
179
|
+
"No extra text is allowed on the table header lines. " +
|
|
180
|
+
"Text was detected to the right of the table headers; aborting. "
|
|
181
|
+
end
|
|
182
|
+
last_cell = last_cell.split('#').first.strip
|
|
183
|
+
[first_cell] + cells.map(&:strip) + [last_cell]
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def table_row
|
|
187
|
+
if @line.strip =~ /^\[(.+)\],(\s*|\s*#.*)$/
|
|
188
|
+
cells = $1
|
|
189
|
+
end_of_row_comment = $2
|
|
190
|
+
cells = cells.split(' , ').map(&:strip)
|
|
191
|
+
[cells, end_of_row_comment]
|
|
192
|
+
else
|
|
193
|
+
raise FormattingError,
|
|
194
|
+
"Only properly formatted table rows expected. " +
|
|
195
|
+
"For example, comments can only appear at the end of table rows, not " +
|
|
196
|
+
"between them. Aborting."
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
class Prettifier
|
|
205
|
+
|
|
206
|
+
def initialize(table)
|
|
207
|
+
@table = table
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def prettify
|
|
211
|
+
output_lines = []
|
|
212
|
+
output_lines += build_header_row
|
|
213
|
+
@table.rows.each_with_index do |cells, index|
|
|
214
|
+
if cells.size != @table.number_of_columns
|
|
215
|
+
if cells.size > 0
|
|
216
|
+
raise FormattingError,
|
|
217
|
+
"Wrong number of table cells in row #{cells.first}. " +
|
|
218
|
+
"Expected #{@table.number_of_columns} cells, got #{cells.size}. " +
|
|
219
|
+
"Remember that if you put Ruby expressions inside of table cells, the " +
|
|
220
|
+
"expressions should not have commas surrounded by spaces or the " +
|
|
221
|
+
"formatter gets confused."
|
|
222
|
+
else
|
|
223
|
+
raise FormattingError,
|
|
224
|
+
"One of the tables has the wrong number of cells."
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
if cells.map(&:strip).any?(&:blank?)
|
|
228
|
+
raise FormattingError,
|
|
229
|
+
"You have at least one empty cell in row ##{index+1}."
|
|
230
|
+
end
|
|
231
|
+
for column in (0..@table.number_of_columns-1)
|
|
232
|
+
cells[column] = build_cell(cells[column], @table.column_width(column))
|
|
233
|
+
end
|
|
234
|
+
line = cells.join(',')
|
|
235
|
+
line = indent('[' + line + '],')
|
|
236
|
+
end_of_row_comment = @table.end_of_row_comments[index]
|
|
237
|
+
unless end_of_row_comment.blank?
|
|
238
|
+
line += ' ' + end_of_row_comment.strip
|
|
239
|
+
end
|
|
240
|
+
output_lines << line
|
|
241
|
+
end
|
|
242
|
+
output_lines += build_header_row
|
|
243
|
+
output_lines
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
private
|
|
247
|
+
|
|
248
|
+
def build_cell(text, width)
|
|
249
|
+
padding = ' ' * 4
|
|
250
|
+
padding + text.ljust(width) + padding
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def indent(s)
|
|
254
|
+
' ' * @table.indentation + s
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def build_header_row
|
|
258
|
+
output_lines = []
|
|
259
|
+
column = 0
|
|
260
|
+
headings = @table.header_row.map do |heading|
|
|
261
|
+
result = build_cell(heading, @table.column_width(column))
|
|
262
|
+
column += 1
|
|
263
|
+
result
|
|
264
|
+
end
|
|
265
|
+
header = headings.join('|')
|
|
266
|
+
header_divider = indent('#' + ('-' * header.size) + '#')
|
|
267
|
+
header = indent('#' + header + '#')
|
|
268
|
+
output_lines << header_divider
|
|
269
|
+
output_lines << header
|
|
270
|
+
output_lines << header_divider
|
|
271
|
+
output_lines
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Tabulous
|
|
2
|
+
|
|
3
|
+
class Css
|
|
4
|
+
attr_accessor :scaffolding
|
|
5
|
+
attr_accessor :background_color
|
|
6
|
+
attr_accessor :text_color
|
|
7
|
+
attr_accessor :active_tab_color
|
|
8
|
+
attr_accessor :hover_tab_color
|
|
9
|
+
attr_accessor :inactive_tab_color
|
|
10
|
+
attr_accessor :inactive_text_color
|
|
11
|
+
def initialize
|
|
12
|
+
@scaffolding = false
|
|
13
|
+
@background_color = '#ccc'
|
|
14
|
+
@text_color = '#444'
|
|
15
|
+
@active_tab_color = 'white'
|
|
16
|
+
@hover_tab_color = '#ddd'
|
|
17
|
+
@inactive_tab_color = '#aaa'
|
|
18
|
+
@inactive_text_color = '#888'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
mattr_accessor :always_render_subtabs
|
|
23
|
+
@@always_render_subtabs = false
|
|
24
|
+
|
|
25
|
+
mattr_accessor :active_tab_clickable
|
|
26
|
+
@@active_tab_clickable = false
|
|
27
|
+
|
|
28
|
+
mattr_accessor :raise_error_if_no_tab_found
|
|
29
|
+
@@raise_error_if_no_tab_found = true
|
|
30
|
+
|
|
31
|
+
mattr_accessor :css
|
|
32
|
+
@@css = Css.new
|
|
33
|
+
|
|
34
|
+
mattr_accessor :html5
|
|
35
|
+
@@html5 = false
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'tabulous'
|
|
2
|
+
require 'rails'
|
|
3
|
+
|
|
4
|
+
module Tabulous
|
|
5
|
+
class Railtie < Rails::Railtie
|
|
6
|
+
rake_tasks do
|
|
7
|
+
load "tasks/tabulous.rake"
|
|
8
|
+
end
|
|
9
|
+
initializer 'tabulous.helper' do |app|
|
|
10
|
+
ActionView::Base.send :include, Tabulous::Helpers
|
|
11
|
+
end
|
|
12
|
+
initializer 'tabulous.reload' do |app|
|
|
13
|
+
ActiveSupport.on_load(:action_controller) do
|
|
14
|
+
if Rails.env.development?
|
|
15
|
+
before_filter do
|
|
16
|
+
# reload tabulous initializer on every request if in development mode
|
|
17
|
+
load File.join(Rails.root.to_s, 'config/initializers/tabulous.rb')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/tabulous/tab.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
module Tabulous
|
|
2
|
+
|
|
3
|
+
class Tab
|
|
4
|
+
|
|
5
|
+
attr_reader :name, :parent
|
|
6
|
+
attr_accessor :subtabs
|
|
7
|
+
|
|
8
|
+
def initialize(name, text, path, visible, enabled)
|
|
9
|
+
@name = name
|
|
10
|
+
name = name.to_s
|
|
11
|
+
if name.ends_with? '_tab'
|
|
12
|
+
@kind = :tab
|
|
13
|
+
elsif name.ends_with? '_subtab'
|
|
14
|
+
@kind = :subtab
|
|
15
|
+
else
|
|
16
|
+
raise TabNameError,
|
|
17
|
+
"Incorrect tab name: '#{name}'. Tab names must end with _tab or _subtab."
|
|
18
|
+
end
|
|
19
|
+
@text = text
|
|
20
|
+
@path = path
|
|
21
|
+
@visible = visible
|
|
22
|
+
@enabled = enabled
|
|
23
|
+
@subtabs = []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def add_parent(tab)
|
|
27
|
+
@parent = tab
|
|
28
|
+
@parent.subtabs = @parent.subtabs + [self]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def subtab?
|
|
32
|
+
@kind == :subtab
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def text(view)
|
|
36
|
+
if @text.is_a? Proc
|
|
37
|
+
run_closure(view, @text)
|
|
38
|
+
else
|
|
39
|
+
@text
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def path(view)
|
|
44
|
+
if @path.is_a? Proc
|
|
45
|
+
run_closure(view, @path)
|
|
46
|
+
else
|
|
47
|
+
@path
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def visible?(view)
|
|
52
|
+
if @visible.is_a? Proc
|
|
53
|
+
!!run_closure(view, @visible)
|
|
54
|
+
else
|
|
55
|
+
!!@visible
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def enabled?(view)
|
|
60
|
+
if @enabled.is_a? Proc
|
|
61
|
+
!!run_closure(view, @enabled)
|
|
62
|
+
else
|
|
63
|
+
!!@enabled
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def run_closure(view, closure)
|
|
70
|
+
if view.respond_to? :instance_exec
|
|
71
|
+
view.instance_exec(&closure) # for Ruby 1.9
|
|
72
|
+
else
|
|
73
|
+
view.instance_eval(&closure)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|