Class: WithFilters::ThemeGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/with_filters/theme/theme_generator.rb

Constant Summary collapse

VIEW_PATH =
'app/views/with_filters'

Instance Method Summary collapse

Instance Method Details

#create_themeObject

A generator to create a theme. Any files missing from the theme will fall back to the original theme. It's recommended that you only generate the files you plan to change.

Examples:

Create an entire theme.

$ rails generate with_filters:theme foo

Create a single file.

$ rails generate with_filters:theme foo filter_form

Since:

  • 0.1.0



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/with_filters/theme/theme_generator.rb', line 22

def create_theme
  empty_directory(VIEW_PATH)

  if partial
    if partial.index('/')
      (extra_dirs, partial_name) = partial.match(/^(.*)\/(.*)$/).captures

      empty_directory("#{VIEW_PATH}/#{file_name}/#{extra_dirs}")

      copy_file(
        "#{extra_dirs}/_#{partial_name.match(/^text_as_/) ? 'text' : partial_name}.html.erb",
        "#{VIEW_PATH}/#{file_name}/#{extra_dirs}/_#{partial_name}.html.erb"
      )
    else
      copy_file("_#{partial}.html.erb", "#{VIEW_PATH}/#{file_name}/_#{partial}.html.erb")
    end
  else
    directory('', "#{VIEW_PATH}/#{file_name}")
  end
end