Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jho406 committed Dec 22, 2024
1 parent cc3d0af commit 15d1e18
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
// scaffold, it will auto append the identifers for you.
//
// e.g {'posts/new': PostNew}
//
//
// If you are using a build tool that supports globbing, you can automatically
// populate `pageIdentiferToPageComponent`. For example, if you are using vite,
// you can use the following snippet instead of manually importing.
//
// ```
// const pageIdentifierToPageComponent = {}
// const pages = import.meta.glob('../views/**/*.jsx', {eager: true})
//
// for (const key in pages) {
// if (pages.hasOwnProperty(key)) {
// const identifier = key.replace("../views/", "").split('.')[0];
// pageIdentifierToPageComponent[identifier] = pages[key].default;
// }
// }
// ```
//
export const pageIdentifierToPageComponent = {
};

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@
// scaffold, it will auto append the identifers for you.
//
// e.g {'posts/new': PostNew}
//
//
// If you are using a build tool that supports globbing, you can automatically
// populate `pageIdentiferToPageComponent`. For example, if you are using vite,
// you can use the following snippet instead of manually importing.
//
// ```
// const pageIdentifierToPageComponent = {}
// const pages = import.meta.glob('../views/**/*.tsx', {eager: true})
//
// for (const key in pages) {
// if (pages.hasOwnProperty(key)) {
// const identifier = key.replace("../views/", "").split('.')[0];
// pageIdentifierToPageComponent[identifier] = pages[key].default;
// }
// }
// ```
//
export const pageIdentifierToPageComponent = {
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ViewCollectionGenerator < Rails::Generators::NamedBase

argument :attributes, type: :array, default: [], banner: "field:type field:type"

class_option :typescript,
type: :boolean,
required: false,
class_option :typescript,
type: :boolean,
required: false,
default: false,
desc: "Use typescript"

Expand Down Expand Up @@ -62,12 +62,16 @@ def append_mapping

component_name = [plural_table_name, action].map(&:camelcase).join

prepend_to_file app_js do
"import #{component_name} from '#{view_path}/#{controller_file_path}/#{action}'\n"
end
if /pageIdentifierToPageComponent = {$/.match?(content)
prepend_to_file app_js do
"import #{component_name} from '#{view_path}/#{controller_file_path}/#{action}'\n"
end

inject_into_file app_js, after: "pageIdentifierToPageComponent = {" do
"\n '#{[controller_file_path, action].join("/")}': #{component_name},"
inject_into_file app_js, after: "pageIdentifierToPageComponent = {" do
"\n '#{[controller_file_path, action].join("/")}': #{component_name},"
end
else
say "Skipping append mapping, you may be using a bundler that supports globing."
end
end
end
Expand Down Expand Up @@ -123,7 +127,7 @@ def js_plural_table_name(casing = :lower)
end

def available_views
%w(index edit show new)
%w[index edit show new]
end

def view_path
Expand All @@ -147,7 +151,7 @@ def filename_with_extensions(name)
def filename_with_js_extensions(name)
[name, :js].join(".")
end

def filename_with_tsx_extensions(name)
[name, :tsx].join(".")
end
Expand All @@ -174,4 +178,3 @@ def attributes_list(attributes = attributes_names)
end
end
end

0 comments on commit 15d1e18

Please sign in to comment.