Sha256: 394c094aee49006c9387b3633da008759710ced8a34c6f736ed3975fd23307f9

Contents?: true

Size: 1.37 KB

Versions: 136

Compression:

Stored size: 1.37 KB

Contents

module BulletTrain
  module Themes
    module Application
      def self.install_theme(theme_name)
        unless theme_name == "light" || Dir.exist?("app/views/themes/#{theme_name}")
          raise "We could not find '#{theme_name}'. Please eject Bullet Train's standard views to your main application first by using `rake bullet_train:themes:light:eject[custom_theme_name_here]`".red
        end

        # Grabs the current theme from
        # def current_theme
        #   :theme_name
        # end
        current_theme_regexp = /(^    :)(.*)/
        current_theme = nil

        new_lines = []
        [
          "./app/helpers/application_helper.rb",
          "./Procfile.dev",
          "./package.json"
        ].each do |file|
          File.open(file, "r") do |f|
            new_lines = f.readlines
            new_lines = new_lines.map do |line|
              # Make sure we get the current theme before trying to replace it in any of the files.
              # We grab it from the first file in the array above.
              current_theme = line.scan(current_theme_regexp).flatten.last if line.match?(current_theme_regexp)

              line.gsub!(/#{current_theme}/, theme_name) unless current_theme.nil?
              line
            end
          end

          File.open(file, "w") do |f|
            f.puts new_lines.join
          end
        end
      end
    end
  end
end

Version data entries

136 entries across 136 versions & 1 rubygems

Version Path
bullet_train-themes-1.10.0 lib/tasks/application.rb
bullet_train-themes-1.9.0 lib/tasks/application.rb
bullet_train-themes-1.8.5 lib/tasks/application.rb
bullet_train-themes-1.8.4 lib/tasks/application.rb
bullet_train-themes-1.8.3 lib/tasks/application.rb
bullet_train-themes-1.8.2 lib/tasks/application.rb
bullet_train-themes-1.8.1 lib/tasks/application.rb
bullet_train-themes-1.8.0 lib/tasks/application.rb
bullet_train-themes-1.7.23 lib/tasks/application.rb
bullet_train-themes-1.7.22 lib/tasks/application.rb
bullet_train-themes-1.7.21 lib/tasks/application.rb
bullet_train-themes-1.7.20 lib/tasks/application.rb
bullet_train-themes-1.7.19 lib/tasks/application.rb
bullet_train-themes-1.7.18 lib/tasks/application.rb
bullet_train-themes-1.7.17 lib/tasks/application.rb
bullet_train-themes-1.7.16 lib/tasks/application.rb
bullet_train-themes-1.7.15 lib/tasks/application.rb
bullet_train-themes-1.7.14 lib/tasks/application.rb
bullet_train-themes-1.7.13 lib/tasks/application.rb
bullet_train-themes-1.7.12 lib/tasks/application.rb