Revision 1298:4f746d8966dd .svn/pristine/38
| .svn/pristine/38/3813f5e1b5a3dcfe71214c111cf9817ac22039cc.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
class GroupCustomField < CustomField |
|
| 19 |
def type_name |
|
| 20 |
:label_group_plural |
|
| 21 |
end |
|
| 22 |
end |
|
| .svn/pristine/38/383b53ea01b1aa0055dd414210668c6694327465.svn-base | ||
|---|---|---|
| 1 |
<h2><%= link_to l(:label_tracker_plural), trackers_path %> » <%= l(:field_summary) %></h2> |
|
| 2 |
|
|
| 3 |
<% if @trackers.any? %> |
|
| 4 |
<%= form_tag fields_trackers_path do %> |
|
| 5 |
<div class="autoscroll"> |
|
| 6 |
<table class="list"> |
|
| 7 |
<thead> |
|
| 8 |
<tr> |
|
| 9 |
<th></th> |
|
| 10 |
<% @trackers.each do |tracker| %> |
|
| 11 |
<th> |
|
| 12 |
<%= tracker.name %> |
|
| 13 |
<%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.tracker-#{tracker.id}')",
|
|
| 14 |
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
|
|
| 15 |
</th> |
|
| 16 |
<% end %> |
|
| 17 |
</tr> |
|
| 18 |
</thead> |
|
| 19 |
<tbody> |
|
| 20 |
<tr class="group open"> |
|
| 21 |
<td colspan="<%= @trackers.size + 1 %>"> |
|
| 22 |
<span class="expander" onclick="toggleRowGroup(this);"> </span> |
|
| 23 |
<%= l(:field_core_fields) %> |
|
| 24 |
</td> |
|
| 25 |
</tr> |
|
| 26 |
<% Tracker::CORE_FIELDS.each do |field| %> |
|
| 27 |
<tr class="<%= cycle("odd", "even") %>">
|
|
| 28 |
<td> |
|
| 29 |
<%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.core-field-#{field}')",
|
|
| 30 |
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
|
|
| 31 |
<%= l("field_#{field}".sub(/_id$/, '')) %>
|
|
| 32 |
</td> |
|
| 33 |
<% @trackers.each do |tracker| %> |
|
| 34 |
<td align="center"> |
|
| 35 |
<%= check_box_tag "trackers[#{tracker.id}][core_fields][]", field, tracker.core_fields.include?(field),
|
|
| 36 |
:class => "tracker-#{tracker.id} core-field-#{field}" %>
|
|
| 37 |
</td> |
|
| 38 |
<% end %> |
|
| 39 |
</tr> |
|
| 40 |
<% end %> |
|
| 41 |
<% if @custom_fields.any? %> |
|
| 42 |
<tr class="group open"> |
|
| 43 |
<td colspan="<%= @trackers.size + 1 %>"> |
|
| 44 |
<span class="expander" onclick="toggleRowGroup(this);"> </span> |
|
| 45 |
<%= l(:label_custom_field_plural) %> |
|
| 46 |
</td> |
|
| 47 |
</tr> |
|
| 48 |
<% @custom_fields.each do |field| %> |
|
| 49 |
<tr class="<%= cycle("odd", "even") %>">
|
|
| 50 |
<td> |
|
| 51 |
<%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('input.custom-field-#{field.id}')",
|
|
| 52 |
:title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %>
|
|
| 53 |
<%= field.name %> |
|
| 54 |
</td> |
|
| 55 |
<% @trackers.each do |tracker| %> |
|
| 56 |
<td align="center"> |
|
| 57 |
<%= check_box_tag "trackers[#{tracker.id}][custom_field_ids][]", field.id, tracker.custom_fields.include?(field),
|
|
| 58 |
:class => "tracker-#{tracker.id} custom-field-#{field.id}" %>
|
|
| 59 |
</td> |
|
| 60 |
<% end %> |
|
| 61 |
</tr> |
|
| 62 |
<% end %> |
|
| 63 |
<% end %> |
|
| 64 |
</tbody> |
|
| 65 |
</table> |
|
| 66 |
</div> |
|
| 67 |
<p><%= submit_tag l(:button_save) %></p> |
|
| 68 |
<% @trackers.each do |tracker| %> |
|
| 69 |
<%= hidden_field_tag "trackers[#{tracker.id}][core_fields][]", '' %>
|
|
| 70 |
<%= hidden_field_tag "trackers[#{tracker.id}][custom_field_ids][]", '' %>
|
|
| 71 |
<% end %> |
|
| 72 |
<% end %> |
|
| 73 |
<% else %> |
|
| 74 |
<p class="nodata"><%= l(:label_no_data) %></p> |
|
| 75 |
<% end %> |
|
| 76 |
|
|
| 77 |
<% html_title l(:field_summary) %> |
|
| .svn/pristine/38/387d439159b4d0ddd79c12022e45def5fc069c4f.svn-base | ||
|---|---|---|
| 1 |
# Redmine - project management software |
|
| 2 |
# Copyright (C) 2006-2011 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 |
|
|
| 18 |
class EnabledModule < ActiveRecord::Base |
|
| 19 |
belongs_to :project |
|
| 20 |
|
|
| 21 |
validates_presence_of :name |
|
| 22 |
validates_uniqueness_of :name, :scope => :project_id |
|
| 23 |
|
|
| 24 |
after_create :module_enabled |
|
| 25 |
|
|
| 26 |
private |
|
| 27 |
|
|
| 28 |
# after_create callback used to do things when a module is enabled |
|
| 29 |
def module_enabled |
|
| 30 |
case name |
|
| 31 |
when 'wiki' |
|
| 32 |
# Create a wiki with a default start page |
|
| 33 |
if project && project.wiki.nil? |
|
| 34 |
Wiki.create(:project => project, :start_page => 'Wiki') |
|
| 35 |
end |
|
| 36 |
end |
|
| 37 |
end |
|
| 38 |
end |
|
| .svn/pristine/38/389e9dcc20c4e06169902989d099cd6ec772aa7a.svn-base | ||
|---|---|---|
| 1 |
= EDGE |
|
| 2 |
|
|
| 3 |
* Samuel Williams (http://www.oriontransfer.co.nz/): |
|
| 4 |
Thanks to Tekin for his patches. |
|
| 5 |
Updated migrations system to tie in more closely with the current rails mechanism. |
|
| 6 |
Rake task for updating database schema info |
|
| 7 |
rake db:migrate:upgrade_plugin_migrations |
|
| 8 |
Please see http://engines.lighthouseapp.com/projects/10178-engines-plugin/tickets/17 for more information. |
|
| 9 |
|
|
| 10 |
* Refactored the view loading to work with changes in Edge Rails |
|
| 11 |
|
|
| 12 |
* Fixed integration of plugin migrations with the new, default timestamped migrations in Edge Rails |
|
| 13 |
|
|
| 14 |
* Refactored tests into the plugin itself - the plugin can now generate its own test_app harness and run tests within it. |
|
| 15 |
|
|
| 16 |
|
|
| 17 |
= 2.0.0 - (ANOTHER) MASSIVE INTERNAL REFACTORING |
|
| 18 |
|
|
| 19 |
* Engines now conforms to the new plugin loading mechanism, delegating plugin load order and lots of other things to Rails itself. |
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
= 1.2.2 |
|
| 24 |
|
|
| 25 |
* Added the ability to code mix different types of files, cleaning up the existing code-mixing implementation slightly (Ticket #271) |
|
| 26 |
|
|
| 27 |
|
|
| 28 |
= 1.2.1 |
|
| 29 |
|
|
| 30 |
* Added documentation to clarify some of the issues with Rails unloading classes that aren't required using "require_dependency" (Ticket #266) |
|
| 31 |
|
|
| 32 |
* Fixed a bug where test_help was being loaded when it wasn't needed, and was actually causing problems (Ticket #265) |
|
| 33 |
|
|
| 34 |
|
|
| 35 |
= 1.2.0 - MASSIVE INTERNAL REFACTORING |
|
| 36 |
|
|
| 37 |
* !!!Support for Rails < 1.2 has been dropped!!!; if you are using Rails =< 1.1.6, please use Engines 1.1.6, available from http://svn.rails-engines.org/engines/tags/rel_1.1.6 |
|
| 38 |
|
|
| 39 |
* Engines are dead! Long live plugins! There is now no meaningful notion of an engine - all plugins can take advantage of the more powerful features that the engines plugin provides by including app directories, etc. |
|
| 40 |
|
|
| 41 |
* Init_engine.rb is no longer used; please use the plugin-standard init.rb instead. |
|
| 42 |
|
|
| 43 |
* Engines.start is no longer required; please use the config.plugins array provided by Rails instead |
|
| 44 |
|
|
| 45 |
* To get the most benefit from Engines, set config.plugins to ["engines", "*"] to load the engines plugin first, and then all other plugins in their normal order after. |
|
| 46 |
|
|
| 47 |
* Access all loaded plugins via the new Rails.plugins array, and by name using Rails.plugins[:plugin_name]. |
|
| 48 |
|
|
| 49 |
* Access plugin metadata loaded automatically from about.yml: Rails.plugins[:name].about. Plugin#version is provided directly, for easy access. |
|
| 50 |
|
|
| 51 |
* Module.config is has been removed - use mattr_accessor instead, and initialize your default values via the init.rb mechanism. |
|
| 52 |
|
|
| 53 |
* Public asset helpers have been rewritten; instead of engine_stylesheet, now use stylesheet_link_tag :name, :plugin => "plugin_name" |
|
| 54 |
|
|
| 55 |
* Plugin migrations have been reworked to integrate into the main migration stream. Please run script/generate plugin_migration to create plugin migrations in your main application. |
|
| 56 |
|
|
| 57 |
* The fixture method for loading fixtures against any class has been removed; instead, engines will now provide a mechanism for loading fixtures from all plugins, by mirroring fixtures into a common location. |
|
| 58 |
|
|
| 59 |
* All references to engines have been removed; For example, any rake tasks which applied to engines now apply to all plugins. The default Rails rake tasks for plugins are overridden where necessary. |
|
| 60 |
|
|
| 61 |
* Layouts can now be shared via plugins - inspiration gratefully taken from PluginAWeek's plugin_routing :) |
|
| 62 |
|
|
| 63 |
* Actual routing from plugins is now possible, by including routes.rb in your plugin directory and using the from_plugin method in config/routes.rb (Ticket #182) |
|
| 64 |
|
|
| 65 |
* Controllers are no longer loaded twice if they're not present in the normal app/ directory (Ticket #177) |
|
| 66 |
|
|
| 67 |
* The preferred location for javascripts/stylesheets/etc is now 'assets' rather than 'public' |
|
| 68 |
|
|
| 69 |
* Ensure that plugins started before routing have their controllers appropriately added to config.controller_paths (Ticket #258) |
|
| 70 |
|
|
| 71 |
* Removed Engines.version - it's not longer relevant, now we're loading version information from about.yml files. |
|
| 72 |
|
|
| 73 |
* Added a huge amount of documentation to all new modules. |
|
| 74 |
|
|
| 75 |
* Added new warning message if installation of engines 1.2.x is attempted in a Rails 1.1.x application |
|
| 76 |
|
|
| 77 |
* Added details of the removal of the config method to UPGRADING |
|
| 78 |
|
|
| 79 |
* Removed the plugins:info rake task in favour of adding information to script/about via the Rails::Info module (Ticket #261) |
|
| 80 |
|
|
| 81 |
* Improved handling of testing and documentation tasks for plugins |
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
= 1.1.4 |
|
| 86 |
|
|
| 87 |
* Fixed creation of multipart emails (Ticket #190) |
|
| 88 |
|
|
| 89 |
* Added a temporary fix to the code-mixing issue. In your engine's test/test_helper.rb, please add the following lines: |
|
| 90 |
|
|
| 91 |
# Ensure that the code mixing and view loading from the application is disabled |
|
| 92 |
Engines.disable_app_views_loading = true |
|
| 93 |
Engines.disable_app_code_mixing = true |
|
| 94 |
|
|
| 95 |
which will prevent code mixing for controllers and helpers, and loading views from the application. One thing to remember is to load any controllers/helpers using 'require_or_load' in your tests, to ensure that the engine behaviour is respected (Ticket #135) |
|
| 96 |
|
|
| 97 |
* Added tasks to easily test engines individually (Ticket #120) |
|
| 98 |
|
|
| 99 |
* Fixture extensions will now fail with an exception if the corresponding class cannot be loaded (Ticket #138) |
|
| 100 |
|
|
| 101 |
* Patch for new routing/controller loading in Rails 1.1.6. The routing code is now replaced with the contents of config.controller_paths, along with controller paths from any started engines (Ticket #196) |
|
| 102 |
|
|
| 103 |
* Rails' Configuration instance is now stored, and available from all engines and plugins. |
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
= 1.1.3 |
|
| 108 |
|
|
| 109 |
* Fixed README to show 'models' rather than 'model' class (Ticket #167) |
|
| 110 |
* Fixed dependency loading to work with Rails 1.1.4 (Ticket #180) |
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
= 1.1.2 |
|
| 115 |
|
|
| 116 |
* Added better fix to version checking (Ticket #130, jdell@gbdev.com). |
|
| 117 |
|
|
| 118 |
* Fixed generated init_engine.rb so that VERSION module doesn't cause probems (Ticket #131, japgolly@gmail.com) |
|
| 119 |
|
|
| 120 |
* Fixed error with Rails 1.0 when trying to ignore the engine_schema_info table (Ticket #132, snowblink@gmail.com) |
|
| 121 |
|
|
| 122 |
* Re-added old style rake tasks (Ticket #133) |
|
| 123 |
|
|
| 124 |
* No longer adding all subdirectories of <engine>/app or <engine>/lib, as this can cause issues when files are grouped in modules (Ticket #149, kasatani@gmail.com) |
|
| 125 |
|
|
| 126 |
* Fixed engine precidence ordering for Rails 1.1 (Ticket #146) |
|
| 127 |
|
|
| 128 |
* Added new Engines.each method to assist in processing the engines in the desired order (Ticket #146) |
|
| 129 |
|
|
| 130 |
* Fixed annoying error message at appears when starting the console in development mode (Ticket #134) |
|
| 131 |
|
|
| 132 |
* Engines is now super-careful about loading the correct version of Rails from vendor (Ticket #154) |
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
= 1.1.1 |
|
| 137 |
|
|
| 138 |
* Fixed migration rake task failing when given a specific version (Ticket #115) |
|
| 139 |
|
|
| 140 |
* Added new rake task "test:engines" which will test engines (and other plugins) but ensure that the test database is cloned from development beforehand (Ticket #125) |
|
| 141 |
|
|
| 142 |
* Fixed issue where 'engine_schema_info' table was included in schema dumps (Ticket #87) |
|
| 143 |
|
|
| 144 |
* Fixed multi-part emails (Ticket #121) |
|
| 145 |
|
|
| 146 |
* Added an 'install.rb' file to new engines created by the bundled generator, which installs the engines plugin automatically if it doesn't already exist (Ticket #122) |
|
| 147 |
|
|
| 148 |
* Added a default VERSION module to generated engines (Ticket #123) |
|
| 149 |
|
|
| 150 |
* Refactored copying of engine's public files to a method of an Engine instance. You can now call Engines.get(:engine_name).copy_public_files (Ticket #108) |
|
| 151 |
|
|
| 152 |
* Changed engine generator templates from .rb files to .erb files (Ticket #106) |
|
| 153 |
|
|
| 154 |
* Fixed the test_helper.erb file to use the correct testing extensions and not load any schema - the schema will be cloned automatically via rake test:engines |
|
| 155 |
|
|
| 156 |
* Fixed problem when running with Rails 1.1.1 where version wasn't determined correctly (Ticket #129) |
|
| 157 |
|
|
| 158 |
* Fixed bug preventing engines from loading when both Rails 1.1.0 and 1.1.1 gems are installed and in use. |
|
| 159 |
|
|
| 160 |
* Updated version (d'oh!) |
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
= 1.1.0 |
|
| 165 |
|
|
| 166 |
* Improved regexp matching for Rails 1.0 engines with peculiar paths |
|
| 167 |
|
|
| 168 |
* Engine instance objects can be accessed via Engines[:name], an alias for Engines.get(:name) (Ticket #99) |
|
| 169 |
|
|
| 170 |
* init_engine.rb is now processed as the final step in the Engine.start process, so it can access files within the lib directory, which is now in the $LOAD_PATH at that point. (Ticket #99) |
|
| 171 |
|
|
| 172 |
* Clarified MIT license (Ticket #98) |
|
| 173 |
|
|
| 174 |
* Updated Rake tasks to integrate smoothly with Rails 1.1 namespaces |
|
| 175 |
|
|
| 176 |
* Changed the version to "1.1.0 (svn)" |
|
| 177 |
|
|
| 178 |
* Added more information about using the plugin with Edge Rails to the README |
|
| 179 |
|
|
| 180 |
* moved extensions into lib/engines/ directory to enable use of Engines module in extension code. |
|
| 181 |
|
|
| 182 |
* Added conditional require_or_load method which attempts to detect the current Rails version. To use the Edge Rails version of the loading mechanism, add the line: |
|
| 183 |
|
|
| 184 |
* Engines.config :edge, true |
|
| 185 |
|
|
| 186 |
* to your environment.rb file. |
|
| 187 |
|
|
| 188 |
* Merged changes from /branches/edge and /branches/rb_1.0 into /trunk |
|
| 189 |
|
|
| 190 |
* engine_schema_info now respects the prefix/suffixes set for ActiveRecord::Base (Ticket #67) |
|
| 191 |
|
|
| 192 |
* added ActiveRecord::Base.wrapped_table_name(name) method to assist in determining the correct table name |
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
= 1.0.6 |
|
| 197 |
|
|
| 198 |
* Added ability to determine version information for engines: rake engine_info |
|
| 199 |
|
|
| 200 |
* Added a custom logger for the Engines module, to stop pollution of the Rails logs. |
|
| 201 |
|
|
| 202 |
* Added some more tests (in particular, see rails_engines/applications/engines_test). |
|
| 203 |
|
|
| 204 |
* Another attempt at solving Ticket #53 - controllers and helpers should now be loadable from modules, and if a full path (including RAILS_ROOT/ENGINES_ROOT) is given, it should be safely stripped from the require filename such that corresponding files can be located in any active engines. In other words, controller/helper overloading should now completely work, even if the controllers/helpers are in modules. |
|
| 205 |
|
|
| 206 |
* Added (finally) patch from Ticket #22 - ActionMailer helpers should now load |
|
| 207 |
|
|
| 208 |
* Removed support for Engines.start :engine, :engine_name => 'whatever'. It was pointless. |
|
| 209 |
|
|
| 210 |
* Fixed engine name referencing; engine_stylesheet/engine_javascript can now happily use shorthand engine names (i.e. :test == :test_engine) (Ticket #45) |
|
| 211 |
|
|
| 212 |
* Fixed minor documentation error ('Engine.start' ==> 'Engines.start') (Ticket #57)
|
|
| 213 |
|
|
| 214 |
* Fixed double inclusion of RAILS_ROOT in engine_migrate rake task (Ticket #61) |
|
| 215 |
|
|
| 216 |
* Added ability to force config values even if given as a hash (Ticket #62) |
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
|
| 220 |
= 1.0.5 |
|
| 221 |
|
|
| 222 |
* Fixed bug stopping fixtures from loading with PostgreSQL |
|
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
= 1.0.4 |
|
| 227 |
|
|
| 228 |
* Another attempt at loading controllers within modules (Ticket #56) |
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
= 1.0.3 |
|
| 233 |
|
|
| 234 |
* Fixed serious dependency bug stopping controllers being loaded (Ticket #56) |
|
| 235 |
|
|
| 236 |
|
|
| 237 |
|
|
| 238 |
= 1.0.2 |
|
| 239 |
|
|
| 240 |
* Fixed bug with overloading controllers in modules from /app directory |
|
| 241 |
|
|
| 242 |
* Fixed exception thrown when public files couldn't be created; exception is now logged (Ticket #52) |
|
| 243 |
|
|
| 244 |
* Fixed problem with generated test_helper.rb file via File.expand_path (Ticket #50) |
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 248 |
= 1.0.1 |
|
| 249 |
|
|
| 250 |
* Added engine generator for creation of new engines |
|
| 251 |
|
|
| 252 |
* Fixed 'Engine' typo in README |
|
| 253 |
|
|
| 254 |
* Fixed bug in fixtures extensions |
|
| 255 |
|
|
| 256 |
* Fixed /lib path management bug |
|
| 257 |
|
|
| 258 |
* Added method to determine public directory location from Engine object |
|
| 259 |
|
|
| 260 |
* Fixed bug in the error message in get_engine_dir() |
|
| 261 |
|
|
| 262 |
* Added proper component loading |
|
| 263 |
|
|
| 264 |
* Added preliminary tests for the config() methods module |
|
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
= pre-v170 |
|
| 269 |
|
|
| 270 |
* Fixed copyright notices to point to DHH, rather than me. |
|
| 271 |
|
|
| 272 |
* Moved extension require statements into lib/engines.rb, so the will be loaded if another module/file calls require 'engines |
|
| 273 |
|
|
| 274 |
* Added a CHANGELOG file (this file) |
|
| .svn/pristine/38/38ca6dda2ba6a1320c43393fa70400cd1996e3e9.svn-base | ||
|---|---|---|
| 1 |
require 'test/unit' |
|
| 2 |
|
|
| 3 |
$:.unshift File.expand_path('../../../lib', __FILE__)
|
|
| 4 |
require 'coderay' |
|
| 5 |
|
|
| 6 |
class ExamplesTest < Test::Unit::TestCase |
|
| 7 |
|
|
| 8 |
def test_examples |
|
| 9 |
# output as HTML div (using inline CSS styles) |
|
| 10 |
div = CodeRay.scan('puts "Hello, world!"', :ruby).div
|
|
| 11 |
assert_equal <<-DIV, div |
|
| 12 |
<div class="CodeRay"> |
|
| 13 |
<div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Hello, world!</span><span style="color:#710">"</span></span></pre></div> |
|
| 14 |
</div> |
|
| 15 |
DIV |
|
| 16 |
|
|
| 17 |
# ...with line numbers |
|
| 18 |
div = CodeRay.scan(<<-CODE.chomp, :ruby).div(:line_numbers => :table) |
|
| 19 |
5.times do |
|
| 20 |
puts 'Hello, world!' |
|
| 21 |
end |
|
| 22 |
CODE |
|
| 23 |
assert_equal <<-DIV, div |
|
| 24 |
<table class="CodeRay"><tr> |
|
| 25 |
<td class="line-numbers" title="double click to toggle" ondblclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre><a href="#n1" name="n1">1</a>
|
|
| 26 |
<a href="#n2" name="n2">2</a> |
|
| 27 |
<a href="#n3" name="n3">3</a> |
|
| 28 |
</pre></td> |
|
| 29 |
<td class="code"><pre><span style="color:#00D">5</span>.times <span style="color:#080;font-weight:bold">do</span> |
|
| 30 |
puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Hello, world!</span><span style="color:#710">'</span></span> |
|
| 31 |
<span style="color:#080;font-weight:bold">end</span></pre></td> |
|
| 32 |
</tr></table> |
|
| 33 |
DIV |
|
| 34 |
|
|
| 35 |
# output as standalone HTML page (using CSS classes) |
|
| 36 |
page = CodeRay.scan('puts "Hello, world!"', :ruby).page
|
|
| 37 |
assert page[<<-PAGE] |
|
| 38 |
<body style="background-color: white;"> |
|
| 39 |
|
|
| 40 |
<table class="CodeRay"><tr> |
|
| 41 |
<td class="line-numbers" title="double click to toggle" ondblclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>
|
|
| 42 |
</pre></td> |
|
| 43 |
<td class="code"><pre>puts <span class="string"><span class="delimiter">"</span><span class="content">Hello, world!</span><span class="delimiter">"</span></span></pre></td> |
|
| 44 |
</tr></table> |
|
| 45 |
|
|
| 46 |
</body> |
|
| 47 |
PAGE |
|
| 48 |
|
|
| 49 |
# keep scanned tokens for later use |
|
| 50 |
tokens = CodeRay.scan('{ "just": "an", "example": 42 }', :json)
|
|
| 51 |
assert_kind_of CodeRay::TokensProxy, tokens |
|
| 52 |
|
|
| 53 |
assert_equal ["{", :operator, " ", :space, :begin_group, :key,
|
|
| 54 |
"\"", :delimiter, "just", :content, "\"", :delimiter, |
|
| 55 |
:end_group, :key, ":", :operator, " ", :space, |
|
| 56 |
:begin_group, :string, "\"", :delimiter, "an", :content, |
|
| 57 |
"\"", :delimiter, :end_group, :string, ",", :operator, |
|
| 58 |
" ", :space, :begin_group, :key, "\"", :delimiter, |
|
| 59 |
"example", :content, "\"", :delimiter, :end_group, :key, |
|
| 60 |
":", :operator, " ", :space, "42", :integer, |
|
| 61 |
" ", :space, "}", :operator], tokens.tokens |
|
| 62 |
|
|
| 63 |
# produce a token statistic |
|
| 64 |
assert_equal <<-STATISTIC, tokens.statistic |
|
| 65 |
|
|
| 66 |
Code Statistics |
|
| 67 |
|
|
| 68 |
Tokens 26 |
|
| 69 |
Non-Whitespace 15 |
|
| 70 |
Bytes Total 31 |
|
| 71 |
|
|
| 72 |
Token Types (7): |
|
| 73 |
type count ratio size (average) |
|
| 74 |
------------------------------------------------------------- |
|
| 75 |
TOTAL 26 100.00 % 1.2 |
|
| 76 |
delimiter 6 23.08 % 1.0 |
|
| 77 |
operator 5 19.23 % 1.0 |
|
| 78 |
space 5 19.23 % 1.0 |
|
| 79 |
key 4 15.38 % 0.0 |
|
| 80 |
:begin_group 3 11.54 % 0.0 |
|
| 81 |
:end_group 3 11.54 % 0.0 |
|
| 82 |
content 3 11.54 % 4.3 |
|
| 83 |
string 2 7.69 % 0.0 |
|
| 84 |
integer 1 3.85 % 2.0 |
|
| 85 |
|
|
| 86 |
STATISTIC |
|
| 87 |
|
|
| 88 |
# count the tokens |
|
| 89 |
assert_equal 26, tokens.count |
|
| 90 |
|
|
| 91 |
# produce a HTML div, but with CSS classes |
|
| 92 |
div = tokens.div(:css => :class) |
|
| 93 |
assert_equal <<-DIV, div |
|
| 94 |
<div class="CodeRay"> |
|
| 95 |
<div class="code"><pre>{ <span class="key"><span class="delimiter">"</span><span class="content">just</span><span class="delimiter">"</span></span>: <span class="string"><span class="delimiter">"</span><span class="content">an</span><span class="delimiter">"</span></span>, <span class="key"><span class="delimiter">"</span><span class="content">example</span><span class="delimiter">"</span></span>: <span class="integer">42</span> }</pre></div>
|
|
| 96 |
</div> |
|
| 97 |
DIV |
|
| 98 |
|
|
| 99 |
# highlight a file (HTML div); guess the file type base on the extension |
|
| 100 |
require 'coderay/helpers/file_type' |
|
| 101 |
assert_equal :ruby, CodeRay::FileType[__FILE__] |
|
| 102 |
|
|
| 103 |
# get a new scanner for Python |
|
| 104 |
python_scanner = CodeRay.scanner :python |
|
| 105 |
assert_kind_of CodeRay::Scanners::Python, python_scanner |
|
| 106 |
|
|
| 107 |
# get a new encoder for terminal |
|
| 108 |
terminal_encoder = CodeRay.encoder :term |
|
| 109 |
assert_kind_of CodeRay::Encoders::Terminal, terminal_encoder |
|
| 110 |
|
|
| 111 |
# scanning into tokens |
|
| 112 |
tokens = python_scanner.tokenize 'import this; # The Zen of Python' |
|
| 113 |
assert_equal ["import", :keyword, " ", :space, "this", :include, |
|
| 114 |
";", :operator, " ", :space, "# The Zen of Python", :comment], tokens |
|
| 115 |
|
|
| 116 |
# format the tokens |
|
| 117 |
term = terminal_encoder.encode_tokens(tokens) |
|
| 118 |
assert_equal "\e[1;31mimport\e[0m \e[33mthis\e[0m; \e[37m# The Zen of Python\e[0m", term |
|
| 119 |
|
|
| 120 |
# re-using scanner and encoder |
|
| 121 |
ruby_highlighter = CodeRay::Duo[:ruby, :div] |
|
| 122 |
div = ruby_highlighter.encode('puts "Hello, world!"')
|
|
| 123 |
assert_equal <<-DIV, div |
|
| 124 |
<div class="CodeRay"> |
|
| 125 |
<div class="code"><pre>puts <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">"</span><span style="color:#D20">Hello, world!</span><span style="color:#710">"</span></span></pre></div> |
|
| 126 |
</div> |
|
| 127 |
DIV |
|
| 128 |
end |
|
| 129 |
|
|
| 130 |
end |
|
Also available in: Unified diff